小白求助一下大神smsapi【2】.php怎么修改编辑代码才能像smsapi【1】.php一样对接成功,弄了好久始终不行,麻烦哪位大神帮帮忙改一下万分谢谢!

smsapi【2】.php:

 <?php   

$url='http://sms.webchinese.cn/web_api/?Uid=账号&Key=接口密钥&smsMob=手机号码&smsText=验证码:8888';
echo Get($url)
function Get($url)
{
$ch = curl_init();
// curl_init()需要php_curl.dll扩展
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
return $file_contents;
}                                                             

smsapi【1】.php:

<?php
/*
 *		秒嘀验证码发送接口类
 * 		By:somnus  
 * 		Time:2016-12-15 21:33 
 * */
class Smsapi{
protected $sendurl = "https://smssh1.253.com/msg/send/json";


//发送验证码
//成功返回0,失败返回错误代码
public function send($number,$cont){
	$user = "xxxxxxx"; //短信平台帐号
	$pass = "xxxxxxx"; //短信平台密码
	//$sendurl = $this->sendurl."msg/send?un=".$user."&pw=".$pass."&phone=".$number."&msg=".urlencode($cont);
	
	$postArr = array (
		'account' => $user,
		'password' => $pass,
		'phone' => $number,
		'msg' => urlencode($cont)
	);
	$result = $this->postHTTPS($this->sendurl,$postArr);
	//$sendurl = $this->sendurl."sms?u=".$user."&p=".$pass."&m=".$number."&c=".urlencode($cont);
	//$result =file_get_contents($sendurl);
	$res = json_decode($result);
	if($res->code !="0"){
		return $res->code;
	}else{
		return 0;
	}
	return 0;
	
//		$nowdate = date("YmdHis");
//		$data = array(
//			'accountSid' => C('cfg_smssid'),
//			'smsContent' => $cont,
//			'to'		 => $number,
//			'timestamp'	 => $nowdate,
//			'sig'		 => md5(C('cfg_smssid').C('cfg_smstoken').$nowdate)
//		);
//		$res = $this->postHTTPS($this->sendurl,$data);
//		$res = json_decode($res);
//		if($res->respCode != "00000"){
//			return $res->respCode;
//		}
//		return 0;
}


private function postHTTPS($url,$postFields) {
    $postFields = json_encode($postFields);
	$ch = curl_init ();
	curl_setopt( $ch, CURLOPT_URL, $url ); 
	curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
		'Content-Type: application/json; charset=utf-8'   //json版本需要填写  Content-Type: application/json;
		)
	);
	curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); 
	curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
	curl_setopt( $ch, CURLOPT_POST, 1 );
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $postFields);
    curl_setopt( $ch, CURLOPT_TIMEOUT,60); 
    curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0);
	$ret = curl_exec ( $ch );
    if (false == $ret) {
        $result = curl_error(  $ch);
    } else {
        $rsp = curl_getinfo( $ch, CURLINFO_HTTP_CODE);
        if (200 != $rsp) {
            $result = "请求状态 ". $rsp . " " . curl_error($ch);
        } else {
            $result = $ret;
        }
    }
	curl_close ( $ch );
	return $result;
 	}

}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值