sms.php 9.1 KB

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