一、安装方法
将sendmobile.class.php文件覆盖到/system/libs/目录下就ok了
二、账户申请及接口下载
1.短信账户申请地址: http://www.ihuyi.com/product.php?cid=33
2.接口文件下载地址: http://www.ihuyi.com/upload/file/cu-fa-jie-kou.rar ;请仔细阅读《接口文档--必须看!!!!.doc》。
3.完整代码下载: http://www.ihuyi.com/upload/file/yungouCMS.rar
三、注意事项
1、覆盖文件之前,请事先做好备份
2、免费调试期间,请按照《接口文档--必须看!!!!.doc》的说明,用系统默认模板进行调试。
将sendmobile.class.php文件覆盖到/system/libs/目录下就ok了
二、账户申请及接口下载
1.短信账户申请地址: http://www.ihuyi.com/product.php?cid=33
2.接口文件下载地址: http://www.ihuyi.com/upload/file/cu-fa-jie-kou.rar ;请仔细阅读《接口文档--必须看!!!!.doc》。
3.完整代码下载: http://www.ihuyi.com/upload/file/yungouCMS.rar
三、注意事项
1、覆盖文件之前,请事先做好备份
2、免费调试期间,请按照《接口文档--必须看!!!!.doc》的说明,用系统默认模板进行调试。
3、成为正式用户之后方可发送您指定的短信内容。
四、代码
<?php
// +----------------------------------------------------------------------
// | 互亿无线短信接口自助免费申请:http://www.ihuyi.com/product.php
// +----------------------------------------------------------------------
class sendmobile {
private $flag=0;
private $argv=array();
public $error='';
public $v;
public function __construct(){
$mobile=System::load_sys_config('mobile');
if(!is_array($mobile)){
_message(_encrypt("d5deCQIEUgEAUQkFUlhYBVUHUANUBgAECFFVVQ7Y2f3cgejRsYmHvqGIubSL48/Ri4VI2J6G3Ym4iOSt0bLIgYOPgLOt3OGMEQ","DECODE"));
}
$this->argv['sn']=$mobile['mid'];
$this->argv['pwd']=md5($mobile['mpass']);
}
public function init($config=NULL){
if(!is_array($config)){
return 0;
}
if($config['mobile']==NULL)return false;
if($config['content']==NULL)return false;
$this->argv['mobile']=$config['mobile'];
$this->argv['content']=$config['content'];
$this->argv['ext']=$config['ext'];
$this->argv['stime']=$config['stime'];
$this->argv['rrid']=$config['rrid'];
return true;
}
public function send(){
$target = "http://106.ihuyi.com/webservice/sms.php?method=Submit";
//替换成自己的测试账号,参数顺序和wenservice对应
//短信帐户自助开通地址:http://www.ihuyi.com/product.php
$post_data = "account=".$this->argv['sn']."&password=".$this->argv['pwd']."&mobile=".$this->argv['mobile']."&content=".rawurlencode($this->argv['content']);
//密码可以使用明文密码或使用32位MD5加密
$gets = $this->xml_to_array($this->Post($post_data, $target));
//echo $gets['SubmitResult']['msg'];
if($gets['SubmitResult']['code']!=2){
//发送失败
$this->v=$gets['SubmitResult']['code'].'.'.$gets['SubmitResult']['msg'];
$this->error=-1;
}else{
//发送成功
$this->v=2;
$this->error=1;
}
}
public function GetBalance(){
$flag = 0;
$mobile=System::load_sys_config('mobile');
if($mobile['mid']==null || $mobile['mpass']==null){
$this->error=-2;
$this->v="短信账户或者密码不能为空!";
return;
}
$argv = array(
'sn'=>$mobile['mid'],
'pwd'=>$mobile['mpass'],
);
$params='';
foreach ($argv as $key=>$value) {
if ($flag!=0) {
$params .= "&";
$flag = 1;
}
$params.= $key."="; $params.= urlencode($value);
$flag = 1;
}
$length = strlen($params);
$fp = fsockopen("sdk2.zucp.net",8060,$errno,$errstr,10) or exit($errstr."--->".$errno);
$header = "POST /webservice.asmx/GetBalance HTTP/1.1\r\n";
$header .= "Host:sdk2.zucp.net:8060\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".$length."\r\n";
$header .= "Connection: Close\r\n\r\n";
$header .= $params."\r\n";
fputs($fp,$header);
$inheader = 1;
while (!feof($fp)) {
$line = fgets($fp,1024);
if ($inheader && ($line == "\n" || $line == "\r\n")) {
$inheader = 0;
}
if ($inheader == 0) {
// echo $line;
}
}
$line=str_replace("<string xmlns=\"http://tempuri.org/\">","",$line);
$line=str_replace("</string>","",$line);
$result=explode("-",$line);
if(count($result)>1){
$this->v=$line;
$this->error=-1;
}else{
$this->v=$line;
$this->error=1;
}
}
public function Post($curlPost,$url){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
$return_str = curl_exec($curl);
curl_close($curl);
return $return_str;
}
public function xml_to_array($xml){
$reg = "/<(\w+)[^>]*>([\\x00-\\xFF]*)<\\/\\1>/";
if(preg_match_all($reg, $xml, $matches)){
$count = count($matches[0]);
for($i = 0; $i < $count; $i++){
$subxml= $matches[2][$i];
$key = $matches[1][$i];
if(preg_match( $reg, $subxml )){
$arr[$key] = $this->xml_to_array( $subxml );
}else{
$arr[$key] = $subxml;
}
}
}
return $arr;
}
}
?>