Alidayu.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * Alidayu.php UTF-8
  4. * 阿里大鱼短信
  5. *
  6. * @date : 2018/4/23 17:32
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. * https://doc.alidayu.com/docs/doc.htm?spm=a3142.7629140.4.9.E36pdC&treeId=1&articleId=101617&docType=1
  12. */
  13. namespace huolib\sms\driver;
  14. use huolib\sms\SmsType;
  15. use huolib\status\MemberStatus;
  16. use think\Log;
  17. class Alidayu {
  18. protected $config
  19. = [
  20. 'APPKEY' => '',
  21. 'APPSECRET' => '',
  22. 'PRODUCT' => '',
  23. 'SMSTEMPAUTH' => '', //系统身份验证验证码
  24. 'SMSTEMPTEST' => '', //系统短信测试
  25. 'SMSTEMPLOGIN' => '', //系统登录确认验证码
  26. 'SMSTEMPLOGINERROR' => '', //系统登录异常验证码
  27. 'SMSTEMPREG' => '', //系统用户注册验证码
  28. 'SMSTEMPACT' => '', //系统活动确认验证码
  29. 'SMSTEMPPWDMOD' => '', //系统修改密码验证码
  30. 'SMSTEMPINFOMOD' => '', //系统信息变更验证码
  31. "SETEXTEND" => "", //setExtend
  32. "SMSTYPE" => "",//SmsType
  33. "SMSFREESIGNNAME" => "",//SmsFreeSignName
  34. ];
  35. public function __construct() {
  36. if (file_exists(GLOBAL_CONF_PATH."extra/sms/alidayu.php")) {
  37. $_config = include GLOBAL_CONF_PATH."extra/sms/alidayu.php";
  38. } else {
  39. $_config = array();
  40. }
  41. $this->config = array_merge($this->config, $_config);
  42. }
  43. /**
  44. * 标准返回
  45. *
  46. * @param $code
  47. *
  48. * @return mixed
  49. */
  50. private function getReturnByCode($code) {
  51. $_rdata['code'] = $code;
  52. $_rdata['msg'] = MemberStatus::getMsg($code);
  53. return $_rdata;
  54. }
  55. public function send($mobile, $type, $sms_code) {
  56. include EXTEND_PATH."taobao/TopSdk.php";
  57. include EXTEND_PATH."taobao/top/TopClient.php";
  58. include EXTEND_PATH."taobao/top/request/AlibabaAliqinFcSmsNumSendRequest.php";
  59. if (empty($this->config['APPKEY'])) {
  60. Log::write("func=".__FUNCTION__."&class=".__CLASS__." config error", LOG::ERROR);
  61. return MemberStatus::CONFIG_ERROR;
  62. }
  63. $_content = array(
  64. "code" => ''.$sms_code,
  65. "product" => ''.$this->config['PRODUCT']
  66. );
  67. switch ($type) {
  68. case SmsType::SMS_REG:
  69. {
  70. $_template_code = $this->config['SMSTEMPREG'];
  71. break;
  72. }
  73. case SmsType::SMS_LOGIN:
  74. {
  75. $_template_code = $this->config['SMSTEMPLOGIN'];
  76. break;
  77. }
  78. case SmsType::SMS_MODIFY:
  79. {
  80. $_template_code = $this->config['SMSTEMPPWDMOD'];
  81. break;
  82. }
  83. case SmsType::SMS_ID_VERIFY:
  84. {
  85. $_template_code = $this->config['SMSTEMPAUTH'];
  86. break;
  87. }
  88. case SmsType::SMS_FIND_PWD:
  89. {
  90. $_template_code = $this->config['SMSTEMPINFOMOD'];
  91. break;
  92. }
  93. case SmsType::SMS_BIND:
  94. {
  95. $_template_code = $this->config['SMSTEMPINFOMOD'];
  96. break;
  97. }
  98. case SmsType::SMS_OTHER:
  99. {
  100. $_template_code = $this->config['SMSTEMPACT'];
  101. break;
  102. }
  103. default:
  104. {
  105. $_template_code = $this->config['SMSTEMPTEST'];
  106. break;
  107. }
  108. }
  109. $_c = new \TopClient();
  110. $_c->appkey = $this->config['APPKEY'];
  111. $_c->secretKey = $this->config['APPSECRET'];
  112. $_req = new \AlibabaAliqinFcSmsNumSendRequest();
  113. $_req->setExtend($this->config['SETEXTEND']);
  114. $_req->setSmsType($this->config['SMSTYPE']);
  115. $_req->setSmsFreeSignName($this->config['SMSFREESIGNNAME']);
  116. $_req->setSmsParam(json_encode($_content));
  117. $_req->setRecNum($mobile);
  118. $_req->setSmsTemplateCode($_template_code);
  119. $_resp = $_c->execute($_req);
  120. $_resp = (array)$_resp;
  121. if (!empty($_resp['result'])) {
  122. return MemberStatus::NO_ERROR;
  123. } else {
  124. Log::write(
  125. "func=".__FUNCTION__."&class=".__CLASS__."&mobile=".$mobile."&type=".$type."&return_msg=.".json_encode(
  126. $_resp
  127. ), LOG::ERROR
  128. );
  129. return MemberStatus::PHONE_SEND_ERROR;
  130. }
  131. }
  132. }