<?php //短信内容HEX编码,dataCoding 为编码方式,realStr 为短信内容 // dataCoding = 8 ,支持所有国家的语言,建议直接使用 8 function encodeHexStr($dataCoding, $realStr) { if ($dataCoding == 15) { return strtoupper(bin2hex(iconv('UTF-8', 'GBK', $realStr))); } else if ($dataCoding == 3) { return strtoupper(bin2hex(iconv('UTF-8', 'ISO-8859-1', $realStr))); } else if ($dataCoding == 8) { return strtoupper(bin2hex(iconv('UTF-8', 'UCS-2BE', $realStr))); } else { return strtoupper(bin2hex(iconv('UTF-8', 'ASCII', $realStr))); } } // 参数数组 //String fmt = "src={0}&pwd={1}&ServiceID=SEND&dest={2}&sender={3}&msg={4}&codec=8"; $data = array ( 'src' => 'user', // 你的用户名, 必须有值 'pwd' => 'password', // 你的密码, 必须有值 'ServiceID' => 'SEND', //固定,不需要改变 'dest' => '861370xxxxxxx', // 你的目的号码【收短信的电话号码】, 必须有值 'sender' => '', // 你的原号码,可空【大部分国家原号码带不过去,只有少数国家支持透传,所有一般为空】 'codec' => '8', // 编码方式, 与msg中encodeHexStr 对应 // codec=8 Unicode 编码, 3 ISO-8859-1, 0 ASCII 'msg' => encodeHexStr(8,'短信内容') // 编码短信内容 ); $uri = "http://210.51.190.233:8085/mt/mt3.ashx"; // 接口地址 $ch = curl_init(); print_r($ch); curl_setopt ( $ch, CURLOPT_URL, $uri ); curl_setopt ( $ch, CURLOPT_POST, 1 ); curl_setopt ( $ch, CURLOPT_HEADER, 0 ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data ); $return = curl_exec ( $ch ); //$return 返回结果,如果是以 “-” 开头的为发送失败,请查看错误代码,否则为MSGID curl_close ( $ch ); print_r($return); ?>