sms.php 8.5 KB

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