123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <?php
- namespace app\api\controller;
- use AlibabaCloud\Client\AlibabaCloud;
- use AlibabaCloud\Client\Exception\ClientException;
- use AlibabaCloud\Client\Exception\ServerException;
- use app\common\model\StoreBanner;
- use app\common\model\User;
- use think\Db;
- /**
- * @title 不需要验证token接口
- * @controller Expedite
- * @package app\api\controller
- */
- class Expedite extends Base
- {
- public function initialize(){
- parent::initialize();
- parent::setUid();
- }
- /**
- * @title 获取首页轮播图
- * @desc 获取首页轮播图
- * @author qc
- * @url /api/Expedite/getBanner
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:num type:int default:5 desc:查询数量
- * @return name:cover type:srting default:-- desc:图片路径
- */
- public function getBanner()
- {
- $num = input('get.num',5);
- $list = StoreBanner::field('id,cover')
- ->where(['is_deleted'=>0])->limit(0,$num)
- ->order('sort desc ,id desc')->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 发送短信验证码
- * @desc 发送短信验证码
- * @author qc
- * @url /api/Expedite/sendSms
- * @method POST
- * @tag 短信验证码
- * @param name:phone type:int require:1 default:-- desc:要获取验证码的手机号
- * @return name:code type:string default:-- desc:验证码
- */
- public function sendSms(){
- $phone = input('post.phone');
- $user_info = User::where('phone',$phone)->where('is_deleted',0)->field('id,status')->find();
- if($user_info && $user_info['status'] == 0)$this ->error('用户被禁用,请联系官方');
- if(empty($phone)) $this ->error('参数错误');
- $code = rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9);
- AlibabaCloud::accessKeyClient('LTAI5tJ5p12drZegeWVG33xZ', '82UWAiY5e5wH8tSkRvMtqVoGO0h8SB')
- ->regionId('cn-hangzhou')->asDefaultClient();
- try {
- $result = AlibabaCloud::rpc()
- ->product('Dysmsapi')
- ->version('2017-05-25')
- ->action('SendSms')
- ->method('POST')
- ->host('dysmsapi.aliyuncs.com')
- ->options([
- 'query' => [
- 'RegionId' => "cn-hangzhou",
- 'PhoneNumbers' => $phone,
- 'SignName' => "搞一下汽车电子",
- 'TemplateCode' => "SMS_234397351",
- 'TemplateParam' => json_encode(array("code"=>$code)),
- ],
- ])->request();
- $result = $result->toArray();
- if($result['Code'] == "OK") {
- $sms_data = array(
- 'phone'=>$phone,
- 'code'=>$code,
- 'result'=>$result['Message']
- );
- Db::name('store_member_sms')->insert($sms_data);
- $this->success('发送成功',['code'=>$code]);
- }else{
- $this->error('发送失败');
- }
- } catch (ClientException $e) {
- echo $e->getErrorMessage() . PHP_EOL;
- } catch (ServerException $e) {
- echo $e->getErrorMessage() . PHP_EOL;
- }
- }
- /**
- * @title 获取签名
- * @desc 获取签名
- * @url /api/Expedite/getWeChatSign
- * @method POST
- * @param name:url type:string default:-- desc:页面地址
- * @return name:appid type:string default:-- desc:appid
- * @return name:noncestr type:string default:-- desc:随机字符
- * @return name:timestamp type:string default:-- desc:时间戳
- * @return name:sign type:string default:-- desc:签名
- * @return name:ticket type:string default:-- desc:ticket
- **/
- public function getWeChatSign(){
- $urls = input('post.url');
- $appid = config('app.official_account')['appid'];
- $secret = config('app.official_account')['secret'];
- $redis = new Redis();
- $access_token = $redis->get('access_token');
- if (!$access_token){
- $access_token = '';
- $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret";
- $res= http_curl($url);
- if (isset($res['access_token'])){
- $redis->set('access_token',$res['access_token'],'7000');
- $access_token = $res['access_token'];
- }
- }
- $url2 ="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi";
- $res2=http_curl($url2);
- if (!isset($res2) || $res2['errcode']!=0) $this->error('获取ticket失败');
- $timestamp = time();
- $noncestr = get32Str(15);
- $string = "jsapi_ticket=".$res2['ticket']."&noncestr=$noncestr×tamp=$timestamp&url=".$urls;
- $sign = sha1($string);
- $return = [
- 'appid'=>$appid,
- 'noncestr'=>$noncestr,
- 'timestamp'=>$timestamp,
- 'url'=>$urls,
- 'sign'=>$sign,
- 'ticket'=>$res2['ticket']
- ];
- $this->success('成功',$return);
- }
- /**
- * @title 获取平台文案设置
- * @desc 获取平台文案设置
- * @author qc
- * @url /api/Expedite/getSysConfig
- * @method GET
- * @param name:search_name type:string default:-- desc:根据下面名称查(不传查全部的)
- * @return name:agreement type:string default:-- desc:用户协议【使用协议】富文本
- * @return name:notice_title type:string default:-- desc:公告标题【字符串】
- * @return name:notice_content type:string default:-- desc:公告内容【富文本】
- */
- public function getSysConfig(){
- $search_name = input('get.search_name');
- $con_name = $search_name? [$search_name] : ['agreement','notice_title','notice_content'];
- $set = Db::name('system_config')->where('name','in',$con_name)->select();
- $ret = [];
- foreach ($set as $value) {
- $ret[$value['name']]=$value['value'];
- }
- $this->success('获取成功',$ret);
- }
- /**
- * @title 获取店铺信息设置
- * @desc 获取店铺信息设置
- * @author qc
- * @url /api/Expedite/getShopSet
- * @method GET
- * @param name:search_name type:string default:-- desc:根据下面名称查(不传查全部的)
- * @return name:app_name type:string default:-- desc:店铺名称
- * @return name:app_logo type:string default:-- desc:店铺封面
- * @return name:app_address type:string default:-- desc:店铺地址
- * @return name:service_phone type:string default:-- desc:联系电话
- * @return name:service_email type:string default:-- desc:邮箱
- */
- public function getShopSet()
- {
- $con_name = ['app_name','app_logo','app_address','service_phone','service_email'];
- $set = Db::name('system_config')->where('name','in',$con_name)->select();
- $ret = [];
- foreach ($set as $value) {
- $ret[$value['name']]=$value['value'];
- }
- $this->success('获取成功',$ret);
- }
- }
|