Aliyun.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Sms\Lib;
  3. use Dever;
  4. Dever::apply('sdk/aliyun/SignatureHelper');
  5. use Aliyun\DySDKLite\SignatureHelper;
  6. class Aliyun
  7. {
  8. public function send($param, $config)
  9. {
  10. $send = array ();
  11. $send['PhoneNumbers'] = $param['mobile'];
  12. $send['SignName'] = $param['sign'];
  13. $send['TemplateCode'] = $param['skin'];
  14. unset($param['mobile']);
  15. unset($param['sign']);
  16. unset($param['skin']);
  17. if (isset($param['id'])) {
  18. $send['OutId'] = $param['id'];
  19. unset($param['id']);
  20. }
  21. $send['TemplateParam'] = $param;
  22. // *** 需用户填写部分结束, 以下代码若无必要无需更改 ***
  23. if(!empty($send['TemplateParam']) && is_array($send['TemplateParam'])) {
  24. $send['TemplateParam'] = json_encode($send['TemplateParam'], JSON_UNESCAPED_UNICODE);
  25. }
  26. // 初始化SignatureHelper实例用于设置参数,签名以及发送请求
  27. $helper = new SignatureHelper();
  28. // 此处可能会抛出异常,注意catch
  29. $content = $helper->request(
  30. $config['appid'],
  31. $config['appsecret'],
  32. 'dysmsapi.aliyuncs.com',
  33. array_merge($send, array(
  34. 'RegionId' => 'cn-hangzhou',
  35. 'Action' => 'SendSms',
  36. 'Version' => '2017-05-25',
  37. ))
  38. );
  39. return $content;
  40. }
  41. }