message.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. include 'aliyun-php-sdk-core/Config.php';
  3. include_once 'Dysmsapi/Request/V20170525/SendSmsRequest.php';
  4. include_once 'Dysmsapi/Request/V20170525/QuerySendDetailsRequest.php';
  5. function sendSms($Tel,$Verify) {
  6. //此处需要替换成自己的AK信息
  7. $accessKeyId = "LTAISIKNr3IJRm47";
  8. $accessKeySecret = "i5uCDgTiO16ogCXqxawdj91Vuy6ThO";
  9. //短信API产品名
  10. $product = "Dysmsapi";
  11. //短信API产品域名
  12. $domain = "dysmsapi.aliyuncs.com";
  13. //暂时不支持多Region
  14. $region = "cn-hangzhou";
  15. //初始化访问的acsCleint
  16. $profile = DefaultProfile::getProfile($region, $accessKeyId, $accessKeySecret);
  17. DefaultProfile::addEndpoint("cn-hangzhou", "cn-hangzhou", $product, $domain);
  18. $acsClient= new DefaultAcsClient($profile);
  19. $request = new Dysmsapi\Request\V20170525\SendSmsRequest;
  20. //必填-短信接收号码
  21. $request->setPhoneNumbers($Tel);
  22. //必填-短信签名
  23. $request->setSignName("品和消防");
  24. //必填-短信模板Code
  25. $request->setTemplateCode("SMS_75870017");
  26. //选填-假如模板中存在变量需要替换则为必填(JSON格式)
  27. $request->setTemplateParam("{\"codec\":\"".$Verify."\"}");
  28. //print_r($request);
  29. //选填-发送短信流水号
  30. $request->setOutId("1234");
  31. //发起访问请求
  32. $acsResponse = $acsClient->getAcsResponse($request);
  33. //get_object_vars($acsResponse);
  34. var_dump($acsResponse->Message);
  35. }
  36. function querySendDetails() {
  37. //此处需要替换成自己的AK信息
  38. $accessKeyId = "LTAISIKNr3IJRm47";
  39. $accessKeySecret = "i5uCDgTiO16ogCXqxawdj91Vuy6ThO";
  40. //短信API产品名
  41. $product = "Dysmsapi";
  42. //短信API产品域名
  43. $domain = "dysmsapi.aliyuncs.com";
  44. //暂时不支持多Region
  45. $region = "cn-hangzhou";
  46. //初始化访问的acsCleint
  47. $profile = DefaultProfile::getProfile($region, $accessKeyId, $accessKeySecret);
  48. DefaultProfile::addEndpoint("cn-hangzhou", "cn-hangzhou", $product, $domain);
  49. $acsClient= new DefaultAcsClient($profile);
  50. $request = new Dysmsapi\Request\V20170525\QuerySendDetailsRequest();
  51. //必填-短信接收号码
  52. $request->setPhoneNumber("15000011254");
  53. //选填-短信发送流水号
  54. $request->setBizId("abcdefgh");
  55. //必填-短信发送日期,支持近30天记录查询,格式yyyyMMdd
  56. $request->setSendDate("20170525");
  57. //必填-分页大小
  58. $request->setPageSize(10);
  59. //必填-当前页码
  60. $request->setContent(1);
  61. //发起访问请求
  62. $acsResponse = $acsClient->getAcsResponse($request);
  63. var_dump($acsResponse);
  64. }
  65. $res = sendSms('17321172378','66688');
  66. var_dump($res);
  67. querySendDetails();
  68. ?>