ExtendService.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | framework
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://framework.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/framework
  12. // +----------------------------------------------------------------------
  13. namespace app\store\service;
  14. use library\tools\Http;
  15. use think\Db;
  16. /**
  17. * 业务扩展服务
  18. * Class ExtendService
  19. * @package app\store\service
  20. */
  21. class ExtendService
  22. {
  23. /**
  24. * 发送短信验证码
  25. * @param string $mid 会员ID
  26. * @param string $phone 手机号
  27. * @param string $content 短信内容
  28. * @param string $productid 短信通道ID
  29. * @return boolean
  30. * @throws \think\Exception
  31. * @throws \think\exception\PDOException
  32. */
  33. public static function sendSms($mid, $phone, $content, $productid = '676767')
  34. {
  35. $tkey = date("YmdHis");
  36. $data = [
  37. 'tkey' => $tkey,
  38. 'mobile' => $phone,
  39. 'content' => $content,
  40. 'username' => sysconf('sms_zt_username'),
  41. 'productid' => $productid,
  42. 'password' => md5(md5(sysconf('sms_zt_password')) . $tkey),
  43. ];
  44. $result = Http::post('http://www.ztsms.cn/sendNSms.do', $data);
  45. list($code, $msg) = explode(',', $result . ',');
  46. $insert = ['mid' => $mid, 'phone' => $phone, 'content' => $content, 'result' => $result];
  47. Db::name('StoreMemberSmsHistory')->insert($insert);
  48. return intval($code) === 1;
  49. }
  50. /**
  51. * 查询短信余额
  52. * @return array
  53. * @throws \think\Exception
  54. * @throws \think\exception\PDOException
  55. */
  56. public static function querySmsBalance()
  57. {
  58. $tkey = date("YmdHis");
  59. $data = [
  60. 'tkey' => $tkey,
  61. 'username' => sysconf('sms_zt_username'),
  62. 'password' => md5(md5(sysconf('sms_zt_password')) . $tkey),
  63. ];
  64. $result = Http::post('http://www.ztsms.cn/balanceN.do', $data);
  65. if ($result > -1) {
  66. return ['code' => 1, 'num' => $result, 'msg' => '获取短信剩余条数成功!'];
  67. } elseif ($result > -2) {
  68. return ['code' => 0, 'num' => '0', 'msg' => '用户名或者密码不正确!'];
  69. } elseif ($result > -3) {
  70. return ['code' => 0, 'num' => '0', 'msg' => 'tkey不正确!'];
  71. } elseif ($result > -4) {
  72. return ['code' => 0, 'num' => '0', 'msg' => '用户不存在或用户停用!'];
  73. }
  74. }
  75. }