Expedite.php 7.3 KB

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