php天翼开放平台短信发送接口实现方法

前端之家收集整理的这篇文章主要介绍了php天翼开放平台短信发送接口实现方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了PHP天翼开放平台短信发送接口实现方法分享给大家供大家参考。具体分析如下:

临时性需求,研究了一下天翼开发平台的东西,用来发送验证码还是不错的,但是每日限额不多,所以很鸡肋,但是保证100%到达 买的话还是蛮贵的,代码没有做任何优化处理,只是测试是否可以实现接口,用的同学记得完善代码,刚写完老大又说是鸡肋的东西,不用了,代码放在博客记录下,代码如下:

代码如下:
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
$access_token = curl_exec($ch);
curl_close($ch);
$access_token = json_decode($access_token,true);
//获取短信信任码
$timestamp = date('Y-m-d H:i:s');

$param['app_id'] = "app_id=x";
$param['access_token'] = "access_token=".$access_token['access_token'];
$param['timestamp'] = "timestamp=".$timestamp;
ksort($param);
$plaintext = implode("&",$param);
$sign = rawurlencode(base64_encode(hash_hmac('sha1',$plaintext,app_secret,true)));
//echo $sign;exit;
$code = file_get_contents("http://api.189.cn/v2/dm/randcode/token?app_id=x&access_token={$access_token['access_token']}&timestamp=".$timestamp."&sign=".$sign);
$code = json_decode($code,true);
$code = $code['token'];
echo $code;
//下发验证码
unset($param,$sign);
$param['app_id'] = "app_id=x";
$param['access_token'] = "access_token=".$access_token['access_token'];
$param['token'] = "token=".$code;
$param['phone'] = "phone=15091421612";
$param['url'] = "url=http://wx.podapi.com/test.php";
$param['exp_time'] = "exp_time=2";
$param['timestamp'] = "timestamp=".$timestamp;
ksort($param);
$plaintext = implode("&",'xx',true)));

$data = "app_id=x&access_token={$access_token['access_token']}&token={$code}&phone=15091421612&url=http://wx.podapi.com/test.php&exp_time=2&timestamp={$timestamp}&sign=".$sign;
$ch = curl_init("http://api.189.cn/v2/dm/randcode/send");
curl_setopt($ch,false);
// 从证书中检查SSL 加密算法是否存在
curl_setopt($ch,false);
$state = curl_exec($ch);
//var_dump(curl_getinfo($ch));
curl_close($ch);
//echo $state;
?>

希望本文所述对大家的PHP程序设计有所帮助。

原文链接:https://www.f2er.com/php/23053.html

猜你在找的PHP相关文章