首页
导航
博客
电子书
算法
众创
代码
随贴
关于我们
您好,欢迎来到码863代码分享网! 请
[登录]
/
[注册]
搜 索
标题:
*
140
字
TAG标签:
(用空格隔开)
30
字
恢复历史版本:
请选择分类
html
python
javascript
php
sql
c
c++
c#
java
plain
所有人可见
仅自己可见
编辑器:UEditor
编辑器:TinyMCE
编辑器:Editor.md
HTML转MD
HTML转MD2
<p>原文 <a href="https://blog.csdn.net/ygc123189/article/details/75103251" _src="https://blog.csdn.net/ygc123189/article/details/75103251">https://blog.csdn.net/ygc123189/article/details/75103251</a> </p><p><br/></p><p>github <a href="https://github.com/difuer-yl/alisms/blob/master/alisms.php" _src="https://github.com/difuer-yl/alisms/blob/master/alisms.php"></a><a href="https://github.com/qqtxt/aliyun_sms" _src="https://github.com/qqtxt/aliyun_sms">https://github.com/qqtxt/aliyun_sms</a> 亲测可用 2019-9-21</p><p><br/></p><p>官方SDK及DEMO,包含众多的文件夹及文件,一大堆的类,类引用地址也是乱的,没法直接运行。</p><p><br/></p><p> 里面包含多个接口(短信发送API,短信查询API,短信消息API),项目只需要短信发送接口即可。</p><p><br/></p><p> 精简后的代码如下:(精简采用POST方式JSON格式SHA1加密)</p><pre class="brush:php;toolbar:false"> $url = 'http://dysmsapi.aliyuncs.com/'; $accessKeyId = "yourAccessKeyId"; $accessKeySecret = "yourAccessKeySecret"; date_default_timezone_set("GMT"); $Timestamp = date('Y-m-d\TH:i:s\Z'); $parameters = [ 'PhoneNumbers' => '15000000000', 'SignName' => '短信签名', 'TemplateCode' => '短信模板Code', 'TemplateParam' => '{"code":"123456"}', 'OutId' => '1234', 'RegionId' => 'cn-hangzhou', 'AccessKeyId' => $accessKeyId, 'Format' => 'JSON', 'SignatureMethod' => 'HMAC-SHA1', 'SignatureVersion' => '1.0', 'SignatureNonce' => uniqid(), 'Timestamp' => $Timestamp, 'Action' => 'SendSms', 'Version' => '2017-05-25', ]; $Signature = $this->computeSignature($parameters, $accessKeySecret); $parameters['Signature'] = $Signature; echo curl_post($url,$parameters);</pre><pre class="brush:php;toolbar:false"> public function computeSignature($parameters, $accessKeySecret) { ksort($parameters); $canonicalizedQueryString = ''; foreach($parameters as $key => $value) { $canonicalizedQueryString .= '&' . $this->percentEncode($key). '=' . $this->percentEncode($value); } $stringToSign = 'POST'.'&%2F&' . $this->percentencode(substr($canonicalizedQueryString, 1)); $signature = base64_encode(hash_hmac('sha1', $stringToSign, $accessKeySecret."&", true)); return $signature; } protected function percentEncode($str) { $res = urlencode($str); $res = preg_replace('/\+/', '%20', $res); $res = preg_replace('/\*/', '%2A', $res); $res = preg_replace('/%7E/', '~', $res); return $res; }</pre><p><br/></p>
CopyRight 2002~2023 精通2100网 联系邮箱:qqtxt@163.com
版权所有:精通2100网
湘ICP备2023018646号-1
MYSQl共执行 4 个查询,用时 0.002180814743042 秒,PHP脚本用时 0.004737 秒,占用内存 0.515 MB,Gzip 已启用