Home php教程 php手册 php天翼开放平台短信发送接口实现

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

May 25, 2016 pm 04:47 PM

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

<?php
//
date_default_timezone_set(&#39;PRC&#39;);
//获取access_token
$data = "app_id=x&app_secret=x&grant_type=client_credentials";
$ch = curl_init("https://oauth.api.189.cn/emp/oauth2/v2/access_token");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);//使用post提交数据
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);//设置 post提交的数据
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// 从证书中检查SSL加密算法是否存在
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$access_token = curl_exec($ch);
curl_close($ch);
$access_token = json_decode($access_token,true);
//获取短信信任码 www.phprm.com
$timestamp = date(&#39;Y-m-d H:i:s&#39;);
$param[&#39;app_id&#39;] = "app_id=x";
$param[&#39;access_token&#39;] = "access_token=".$access_token[&#39;access_token&#39;];
$param[&#39;timestamp&#39;] = "timestamp=".$timestamp;
ksort($param);
$plaintext = implode("&",$param);
$sign = rawurlencode(base64_encode(hash_hmac(&#39;sha1&#39;,$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[&#39;access_token&#39;]}&timestamp=".$timestamp."&sign=".$sign);
$code = json_decode($code,true);
$code = $code[&#39;token&#39;];
echo $code;
//下发验证码
unset($param,$plaintext,$sign);
$param[&#39;app_id&#39;] = "app_id=x";
$param[&#39;access_token&#39;] = "access_token=".$access_token[&#39;access_token&#39;];
$param[&#39;token&#39;] = "token=".$code;
$param[&#39;phone&#39;] = "phone=15091421612";
$param[&#39;url&#39;] = "url=http://wx.podapi.com/test.php";
$param[&#39;exp_time&#39;] = "exp_time=2";
$param[&#39;timestamp&#39;] = "timestamp=".$timestamp;
ksort($param);
$plaintext = implode("&",$param);
$sign = rawurlencode(base64_encode(hash_hmac(&#39;sha1&#39;,$plaintext,&#39;xx&#39;,true)));
$data = "app_id=x&access_token={$access_token[&#39;access_token&#39;]}&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,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);//使用post提交数据
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);//设置 post提交的数据
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// 从证书中检查SSL www.phprm.com 加密算法是否存在
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$state = curl_exec($ch);
//var_dump(curl_getinfo($ch));
curl_close($ch);
//echo $state;
Copy after login


文章链接:

随便收藏,请保留本文地址!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)