<?php 
header("Content-Type: text/html; charset=utf-8");
$post_data = array();
$post_data['account'] = '';   //帐号
$post_data['pswd'] = '';  //密码
$post_data['msg'] =urlencode(''); //短信内容需要用urlencode编码下
$post_data['mobile'] = ''; //手机号码, 多个用英文状态下的 , 隔开
$post_data['product'] = ''; //产品ID
$post_data['needstatus']=true; //是否需要状态报告,需要true,不需要false
$post_data['extno']='';  //扩展码   可以不用填写
$url='http://120.26.69.248/msg/HttpSendSM?account=123456&pswd=123456789&mobile=13200016985&msg=测试PHP&needstatus=true&product=117502&extno=';
$o='';
foreach ($post_data as $k=>$v)
{
   $o.="$k=".urlencode($v).'&';
}
$post_data=substr($o,0,-1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果需要将结果直接返回到变量里,那加上这句。
$result = curl_exec($ch);
?>

解决方案 »

  1.   

    很简单的问题,是编码的问题假如您的页面是UTF-8编码,短信接口要求你用GB2312编码,你在使用urlencode的时候应该先转码,如:urlencode(mb_convert_encoding("这是短信内容正文","gb2312","UTF-8"))建议只将短信内容使用mb_convert_encoding一下就行了~~~
      

  2.   

    urlencode 一下看看。
      

  3.   

    还有,你写的$url不对。如果你要用curl的post来发送短信息,那么没必要再构造get方式发送的url,改成下面的就行了<?php 
     header("Content-Type: text/html; charset=utf-8");
     $post_data = array();
     $post_data['account'] ="123456'';   //帐号
    $post_data['pswd'] ="123456";  //密码
    $post_data['msg'] =urlencode(mb_convert_encoding("这是短信内容正文","gb2312","UTF-8"));
     //你的短信接口是否要求urlencode我不清楚,但是出现乱码肯定是你的页面的编码和短信接口要求的编码不同(估计短信接口要求gb2312),所以我给你转码了一下;函数参数为:mb_convert_encoding("字符串","目标编码","原始编码")
    $post_data['mobile'] ="18688888888''; //手机号码, 多个用英文状态下的 , 隔开
    $post_data['product'] = ''; //产品ID
     $post_data['needstatus']=true; //是否需要状态报告,需要true,不需要false
     $post_data['extno']='';  //扩展码   可以不用填写
    $url='http://120.26.69.248/msg/HttpSendSM';
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_URL,$url);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
     //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果需要将结果直接返回到变量里,那加上这句。
    $result = curl_exec($ch);
     ?> 
    这才是curl的post发送短信,你一楼的代码混杂了get和post~~~~如果要用get发送,就没有构造post_data数组了
      

  4.   

    msg=测试PHP 这个短信内容要与接口边的编码要一致,如不一至,用mb_convert_encoding 转