sms.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /**
  3. * 手机短信类
  4. *
  5. *
  6. *
  7. * @package library* www.33hao.com好商城V3为你提供售后服务 以便你更好的了解
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class Sms
  11. {
  12. const register_code = 1;
  13. const resetpass_code = 2;
  14. const getbonus_code = 3;
  15. const getbind_code = 4;
  16. /*
  17. * 发送手机短信
  18. * @param unknown $mobile 手机号
  19. * @param unknown $content 短信内容
  20. */
  21. public function send($mobile, $content)
  22. {
  23. $mobile_host_type = C('mobile_host_type');
  24. if ($mobile_host_type == 1) {
  25. return $this->mysend_smsbao($mobile, $content);
  26. } elseif ($mobile_host_type == 2) {
  27. return $this->mysend_yunpian($mobile, $content);
  28. } elseif ($mobile_host_type == 3) {
  29. return $this->mysend_yuntx($mobile, $content);
  30. } elseif ($mobile_host_type == 4) {
  31. $this->send_yunpian($mobile, $content);
  32. }
  33. }
  34. private function send_msg($mobile, $datas, $type)
  35. {
  36. $folder = 'yuntx';
  37. $plugin = str_replace('\\', '', str_replace('/', '', str_replace('.', '', $folder)));
  38. if (!empty($plugin)) {
  39. define('PLUGIN_ROOT', BASE_DATA_PATH . DS . 'api/smsapi');
  40. require_once(PLUGIN_ROOT . DS . $plugin . DS . 'CCPRestSDK.php');
  41. require_once(PLUGIN_ROOT . DS . $plugin . DS . 'SendSMS.php');
  42. return sendSMS($mobile, $datas, $type);
  43. } else {
  44. return -1;
  45. }
  46. }
  47. /*
  48. 您于{$send_time}绑定手机号,验证码是:{$verify_code}。【{$site_name}】
  49. 0 提交成功
  50. 30:密码错误
  51. 40:账号不存在
  52. 41:余额不足
  53. 42:帐号过期
  54. 43:IP地址限制
  55. 50:内容含有敏感词
  56. 51:手机号码不正确
  57. http://api.smsbao.com/sms?u=USERNAME&p=PASSWORD&m=PHONE&c=CONTENT
  58. */
  59. private function mysend_yuntx($mobile, $content)
  60. {
  61. $type = intval($content['type']);
  62. if(array_key_exists('type',$content)) {
  63. unset($content['type']);
  64. }
  65. static $templates = array(self::register_code => '59006', self::resetpass_code => '63477', self::getbonus_code => '63479', self::getbind_code => '59006');
  66. if (!array_key_exists($type, $templates)) return -1;
  67. return $this->send_msg($mobile, $content, $templates[$type]);
  68. }
  69. /*
  70. 您于{$send_time}绑定手机号,验证码是:{$verify_code}。【{$site_name}】
  71. 0 提交成功
  72. 30:密码错误
  73. 40:账号不存在
  74. 41:余额不足
  75. 42:帐号过期
  76. 43:IP地址限制
  77. 50:内容含有敏感词
  78. 51:手机号码不正确
  79. http://api.smsbao.com/sms?u=USERNAME&p=PASSWORD&m=PHONE&c=CONTENT
  80. */
  81. private function mysend_smsbao($mobile, $content)
  82. {
  83. $user_id = urlencode(C('mobile_username')); // 这里填写用户名
  84. $pass = urlencode(C('mobile_pwd')); // 这里填登陆密码
  85. if (!$mobile || !$content || !$user_id || !$pass) return false;
  86. if (is_array($mobile)) $mobile = implode(",", $mobile);
  87. $mobile = urlencode($mobile);
  88. //$content=$content."【我的网站】";
  89. $content = urlencode($content);
  90. $pass = md5($pass);//MD5加密
  91. $url = "http://api.smsbao.com/sms?u=" . $user_id . "&p=" . $pass . "&m=" . $mobile . "&c=" . $content . "";
  92. $res = file_get_contents($url);
  93. //return $res;
  94. $ok = $res == "0";
  95. if ($ok) {
  96. return true;
  97. }
  98. return false;
  99. }
  100. /**
  101. * http://www.yunpian.com/
  102. * 发送手机短信
  103. * @param unknown $mobile 手机号
  104. * @param unknown $content 短信内容
  105. * 0 OK 调用成功,该值为null 无需处理
  106. * 1 请求参数缺失 补充必须传入的参数 开发者
  107. * 2 请求参数格式错误 按提示修改参数值的格式 开发者
  108. * 3 账户余额不足 账户需要充值,请充值后重试 开发者
  109. * 4 关键词屏蔽 关键词屏蔽,修改关键词后重试 开发者
  110. * 5 未找到对应id的模板 模板id不存在或者已经删除 开发者
  111. * 6 添加模板失败 模板有一定的规范,按失败提示修改 开发者
  112. * 7 模板不可用 审核状态的模板和审核未通过的模板不可用 开发者
  113. * 8 同一手机号30秒内重复提交相同的内容 请检查是否同一手机号在30秒内重复提交相同的内容 开发者
  114. * 9 同一手机号5分钟内重复提交相同的内容超过3次 为避免重复发送骚扰用户,同一手机号5分钟内相同内容最多允许发3次 开发者
  115. * 10 手机号黑名单过滤 手机号在黑名单列表中(你可以把不想发送的手机号添加到黑名单列表) 开发者
  116. * 11 接口不支持GET方式调用 接口不支持GET方式调用,请按提示或者文档说明的方法调用,一般为POST 开发者
  117. * 12 接口不支持POST方式调用 接口不支持POST方式调用,请按提示或者文档说明的方法调用,一般为GET 开发者
  118. * 13 营销短信暂停发送 由于运营商管制,营销短信暂时不能发送 开发者
  119. * 14 解码失败 请确认内容编码是否设置正确 开发者
  120. * 15 签名不匹配 短信签名与预设的固定签名不匹配 开发者
  121. * 16 签名格式不正确 短信内容不能包含多个签名【 】符号 开发者
  122. * 17 24小时内同一手机号发送次数超过限制 请检查程序是否有异常或者系统是否被恶意攻击 开发者
  123. * -1 非法的apikey apikey不正确或没有授权 开发者
  124. * -2 API没有权限 用户没有对应的API权限 开发者
  125. * -3 IP没有权限 访问IP不在白名单之内,可在后台"账户设置->IP白名单设置"里添加该IP 开发者
  126. * -4 访问次数超限 调整访问频率或者申请更高的调用量 开发者
  127. * -5 访问频率超限 短期内访问过于频繁,请降低访问频率 开发者
  128. * -50 未知异常 系统出现未知的异常情况 技术支持
  129. * -51 系统繁忙 系统繁忙,请稍后重试 技术支持
  130. * -52 充值失败 充值时系统出错 技术支持
  131. * -53 提交短信失败 提交短信时系统出错 技术支持
  132. * -54 记录已存在 常见于插入键值已存在的记录 技术支持
  133. * -55 记录不存在 没有找到预期中的数据 技术支持
  134. * -57 用户开通过固定签名功能,但签名未设置 联系客服或技术支持设置固定签名 技术支持
  135. * @return bool|string
  136. */
  137. private function mysend_yunpian($mobile, $content)
  138. {
  139. $yunpian = 'yunpian';
  140. $plugin = str_replace('\\', '', str_replace('/', '', str_replace('.', '', $yunpian)));
  141. if (!empty($plugin)) {
  142. define('PLUGIN_ROOT', BASE_DATA_PATH . DS . 'api/smsapi');
  143. require_once(PLUGIN_ROOT . DS . $plugin . DS . 'Send.php');
  144. return send_sms($content, $mobile);
  145. } else {
  146. return false;
  147. }
  148. }
  149. protected function send_yunpian($mobile, $content)
  150. {
  151. $code = $content['code'];
  152. //$time = $content['time'];
  153. $type = intval($content['type']);
  154. static $templates = array(self::register_code => '1382929', self::resetpass_code => '1386969', self::getbonus_code => '1386979', self::getbind_code => '1382929');
  155. if (!array_key_exists($type, $templates)) return -1;
  156. return $this->tpl_send_sms($mobile, $code, $templates[$type]);
  157. }
  158. protected function tpl_send_sms($mobile, $tpl_value, $tpl_id)
  159. {
  160. $yunpian = 'yunpian';
  161. $plugin = str_replace('\\', '', str_replace('/', '', str_replace('.', '', $yunpian)));
  162. Log::record("SMS yunpian send:{$mobile} {$tpl_value} {$tpl_id}", Log::DEBUG);
  163. if (!empty($plugin)) {
  164. $plugin_root = BASE_DATA_PATH . DS . 'api/smsapi';
  165. require_once($plugin_root . DS . $plugin . DS . 'Send.php');
  166. return tpl_send_sms($tpl_id, $tpl_value, $mobile);
  167. } else {
  168. return false;
  169. }
  170. }
  171. }