wupengfei %!s(int64=2) %!d(string=hai) anos
pai
achega
3431168693
Modificáronse 1 ficheiros con 15 adicións e 8 borrados
  1. 15 8
      application/api/controller/UserCenter.php

+ 15 - 8
application/api/controller/UserCenter.php

@@ -4,6 +4,7 @@ use app\common\model\UserLevelRank;
 use app\common\model\UserMessage;
 use app\common\validate\UserVali;
 use EasyWeChat\Factory;
+use think\cache\driver\Redis;
 use think\Db;
 use app\common\model\User;
 /**
@@ -144,11 +145,16 @@ class UserCenter extends Base
 
     public function getToken()
     {
-        $mini_program = config('app.mini_program');
-        var_dump($mini_program);
-        $res = http_get("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$mini_program['app_id']}&secret={$mini_program['secret']}");
-        var_dump($res);
-
+        $redis = new Redis();
+        $access_token = $redis->get('access_token');
+        if($access_token){
+            var_dump($access_token,1111);
+        }else{
+            $mini_program = config('app.mini_program');
+            $res = http_get("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$mini_program['app_id']}&secret={$mini_program['secret']}");
+            $redis->set('access_token',$res['access_token'],7000);
+            var_dump($res['access_token'],2222);
+        }
     }
 
 
@@ -156,8 +162,8 @@ class UserCenter extends Base
     {
        /* $res = curl_post('https://gaoyixia.hdlkeji.com/api/qc/index',[]);
         var_dump($res);die();*/
-
-        $access_token = '63_4isgw4kula9Vprs7bk_Aro08bs4jih5j3QOxGSTYuYIUzj2yAd5qzJVQ_VgKMXfs9bLdwBgKQqePaZEVF_Ft6513iypXUvhoC2ra1qC4wKY0DftHQZIEksisarsJKXhAAACDQ';
+        $redis = new Redis();
+        $access_token = $redis->get('access_token');
         $code = input('code');
         $res = curl_post("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token={$access_token}",
             json_encode(['access_token'=>$access_token,'code'=>$code]));
@@ -166,7 +172,8 @@ class UserCenter extends Base
 
     public function getRid()
     {
-        $access_token = '63_4isgw4kula9Vprs7bk_Aro08bs4jih5j3QOxGSTYuYIUzj2yAd5qzJVQ_VgKMXfs9bLdwBgKQqePaZEVF_Ft6513iypXUvhoC2ra1qC4wKY0DftHQZIEksisarsJKXhAAACDQ';
+        $redis = new Redis();
+        $access_token  = $redis->get('access_token');
         $rid = input('rid');
         $rid = curl_post("https://api.weixin.qq.com/cgi-bin/openapi/rid/get?access_token={$access_token}&",
             json_encode(['access_token'=>$access_token,'rid'=>$rid]));