12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace Sms\Lib;
- use Dever;
- Dever::apply('sdk/aliyun/SignatureHelper');
- use Aliyun\DySDKLite\SignatureHelper;
- class Aliyun
- {
- public function send($param, $config)
- {
- $send = array ();
- $send['PhoneNumbers'] = $param['mobile'];
- $send['SignName'] = $param['sign'];
- $send['TemplateCode'] = $param['skin'];
- unset($param['mobile']);
- unset($param['sign']);
- unset($param['skin']);
- if (isset($param['id'])) {
- $send['OutId'] = $param['id'];
- unset($param['id']);
- }
- $send['TemplateParam'] = $param;
-
- // *** 需用户填写部分结束, 以下代码若无必要无需更改 ***
- if(!empty($send['TemplateParam']) && is_array($send['TemplateParam'])) {
- $send['TemplateParam'] = json_encode($send['TemplateParam'], JSON_UNESCAPED_UNICODE);
- }
- // 初始化SignatureHelper实例用于设置参数,签名以及发送请求
- $helper = new SignatureHelper();
- // 此处可能会抛出异常,注意catch
- $content = $helper->request(
- $config['appid'],
- $config['appsecret'],
- 'dysmsapi.aliyuncs.com',
- array_merge($send, array(
- 'RegionId' => 'cn-hangzhou',
- 'Action' => 'SendSms',
- 'Version' => '2017-05-25',
- ))
- );
- return $content;
- }
- }
|