Expedite.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. namespace app\api\controller;
  3. use AlibabaCloud\Client\AlibabaCloud;
  4. use AlibabaCloud\Client\Exception\ClientException;
  5. use AlibabaCloud\Client\Exception\ServerException;
  6. use app\common\model\StoreBanner;
  7. use app\common\model\User;
  8. use think\cache\driver\Redis;
  9. use think\Db;
  10. /**
  11. * @title 不需要验证token接口
  12. * @controller Expedite
  13. * @package app\api\controller
  14. */
  15. class Expedite extends Base
  16. {
  17. public function initialize(){
  18. parent::initialize();
  19. parent::setUid();
  20. }
  21. /**
  22. * @title 获取首页轮播图
  23. * @desc 获取首页轮播图
  24. * @author qc
  25. * @url /api/Expedite/getBanner
  26. * @method GET
  27. * @header name:Authorization require:1 desc:Token
  28. * @param name:num type:int default:5 desc:查询数量
  29. * @return name:cover type:srting default:-- desc:图片路径
  30. */
  31. public function getBanner()
  32. {
  33. $num = input('get.num',5);
  34. $list = StoreBanner::field('id,cover')
  35. ->where(['is_deleted'=>0])->limit(0,$num)
  36. ->order('sort desc ,id desc')->select()->toArray();
  37. $this->success('ok',['list'=>$list]);
  38. }
  39. /**
  40. * @title 发送短信验证码
  41. * @desc 发送短信验证码
  42. * @author qc
  43. * @url /api/Expedite/sendSms
  44. * @method POST
  45. * @tag 短信验证码
  46. * @param name:phone type:int require:1 default:-- desc:要获取验证码的手机号
  47. * @return name:code type:string default:-- desc:验证码
  48. */
  49. public function sendSms(){
  50. $phone = input('post.phone');
  51. $user_info = User::where('phone',$phone)->where('is_deleted',0)->field('id,status')->find();
  52. if($user_info && $user_info['status'] == 0)$this ->error('用户被禁用,请联系官方');
  53. if(empty($phone)) $this ->error('参数错误');
  54. $code = rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9);
  55. AlibabaCloud::accessKeyClient('LTAI5tJ5p12drZegeWVG33xZ', '82UWAiY5e5wH8tSkRvMtqVoGO0h8SB')
  56. ->regionId('cn-hangzhou')->asDefaultClient();
  57. try {
  58. $result = AlibabaCloud::rpc()
  59. ->product('Dysmsapi')
  60. ->version('2017-05-25')
  61. ->action('SendSms')
  62. ->method('POST')
  63. ->host('dysmsapi.aliyuncs.com')
  64. ->options([
  65. 'query' => [
  66. 'RegionId' => "cn-hangzhou",
  67. 'PhoneNumbers' => $phone,
  68. 'SignName' => "搞一下汽车电子",
  69. 'TemplateCode' => "SMS_234397351",
  70. 'TemplateParam' => json_encode(array("code"=>$code)),
  71. ],
  72. ])->request();
  73. $result = $result->toArray();
  74. if($result['Code'] == "OK") {
  75. $sms_data = array(
  76. 'phone'=>$phone,
  77. 'code'=>$code,
  78. 'result'=>$result['Message']
  79. );
  80. Db::name('store_member_sms')->insert($sms_data);
  81. $this->success('发送成功',['code'=>$code]);
  82. }else{
  83. $this->error('发送失败');
  84. }
  85. } catch (ClientException $e) {
  86. echo $e->getErrorMessage() . PHP_EOL;
  87. } catch (ServerException $e) {
  88. echo $e->getErrorMessage() . PHP_EOL;
  89. }
  90. }
  91. /**
  92. * @title 获取签名
  93. * @desc 获取签名
  94. * @url /api/Expedite/getWeChatSign
  95. * @method POST
  96. * @param name:url type:string default:-- desc:页面地址
  97. * @return name:appid type:string default:-- desc:appid
  98. * @return name:noncestr type:string default:-- desc:随机字符
  99. * @return name:timestamp type:string default:-- desc:时间戳
  100. * @return name:sign type:string default:-- desc:签名
  101. * @return name:ticket type:string default:-- desc:ticket
  102. **/
  103. public function getWeChatSign(){
  104. $urls = input('post.url');
  105. $appid = config('app.official_account')['appid'];
  106. $secret = config('app.official_account')['secret'];
  107. $redis = new Redis();
  108. $access_token = $redis->get('access_token');
  109. if (!$access_token){
  110. $access_token = '';
  111. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret";
  112. $res= http_curl($url);
  113. if (isset($res['access_token'])){
  114. $redis->set('access_token',$res['access_token'],'7000');
  115. $access_token = $res['access_token'];
  116. }
  117. }
  118. $url2 ="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi";
  119. $res2=http_curl($url2);
  120. if (!isset($res2) || $res2['errcode']!=0) $this->error('获取ticket失败');
  121. $timestamp = time();
  122. $noncestr = get32Str(15);
  123. $string = "jsapi_ticket=".$res2['ticket']."&noncestr=$noncestr&timestamp=$timestamp&url=".$urls;
  124. $sign = sha1($string);
  125. $return = [
  126. 'appid'=>$appid,
  127. 'noncestr'=>$noncestr,
  128. 'timestamp'=>$timestamp,
  129. 'url'=>$urls,
  130. 'sign'=>$sign,
  131. 'ticket'=>$res2['ticket']
  132. ];
  133. $this->success('成功',$return);
  134. }
  135. /**
  136. * @title 获取平台文案设置
  137. * @desc 获取平台文案设置
  138. * @author qc
  139. * @url /api/Expedite/getSysConfig
  140. * @method GET
  141. * @param name:search_name type:string default:-- desc:根据下面名称查(不传查全部的)
  142. * @return name:agreement type:string default:-- desc:用户协议【使用协议】富文本
  143. * @return name:notice_title type:string default:-- desc:首页公告标题【字符串】
  144. * @return name:notice_content type:string default:-- desc:首页公告内容【富文本】
  145. * @return name:mall_notice_title type:string default:-- desc:商城公告内容【字符串】
  146. * @return name:mall_notice_content type:string default:-- desc:商城公告内容【富文本】
  147. */
  148. public function getSysConfig(){
  149. $search_name = input('get.search_name');
  150. $con_name = $search_name? [$search_name] : ['agreement','notice_title','notice_content','mall_notice_title','mall_notice_content'];
  151. $set = Db::name('system_config')->where('name','in',$con_name)->select();
  152. $ret = [];
  153. foreach ($set as $value) {
  154. $ret[$value['name']]=$value['value'];
  155. }
  156. $this->success('获取成功',$ret);
  157. }
  158. /**
  159. * @title 获取店铺信息设置
  160. * @desc 获取店铺信息设置
  161. * @author qc
  162. * @url /api/Expedite/getShopSet
  163. * @method GET
  164. * @param name:search_name type:string default:-- desc:根据下面名称查(不传查全部的)
  165. * @return name:app_name type:string default:-- desc:店铺名称
  166. * @return name:app_logo type:string default:-- desc:店铺封面
  167. * @return name:app_address type:string default:-- desc:店铺地址
  168. * @return name:service_phone type:string default:-- desc:联系电话
  169. * @return name:service_email type:string default:-- desc:邮箱
  170. */
  171. public function getShopSet()
  172. {
  173. $con_name = ['app_name','app_logo','app_address','service_phone','service_email'];
  174. $set = Db::name('system_config')->where('name','in',$con_name)->select();
  175. $ret = [];
  176. foreach ($set as $value) {
  177. $ret[$value['name']]=$value['value'];
  178. }
  179. $this->success('获取成功',$ret);
  180. }
  181. }