sms.php 9.0 KB

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