15954078560 2 gadi atpakaļ
vecāks
revīzija
937e87b535
1 mainītis faili ar 100 papildinājumiem un 0 dzēšanām
  1. 100 0
      application/api/controller/Index.php

+ 100 - 0
application/api/controller/Index.php

@@ -6,6 +6,8 @@ use app\common\controller\Api;
 use Think\Cache;
 use think\Db;
 use wxpay;
+use Qcloud\Cos\Client;
+use Qcloud\Cos\Exception\ServiceResponseException;
 
 /**
  * 首页接口
@@ -973,4 +975,102 @@ class Index extends Api
 
         $this->success('分享链接', $rs['link']);
     }
+
+    //生成小程序邀请二维码
+    public function getqrcode() {
+//        $id = input('id', 0, 'intval'); //活动id
+//        if (!$id) {
+//            $this->error('参数缺失');
+//        }
+//        $info = Db::name('active')->find($id);
+//        if (!$info) {
+//            $this->error('活动不存在');
+//        }
+//        if ($info['status'] == 2) {
+//            $this->error('活动已结束');
+//        }
+//        if ($info['status'] == 3) {
+//            $this->error('活动已取消');
+//        }
+
+//        $access_token = Cache::get('access_token');
+        $access_token = '';
+        if (!$access_token) {
+            //获取$access_token
+//            $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.config('wxchatpay.app_id').'&secret='.config('wxchatpay.app_secret');
+            $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx326ed0bf442d2773&secret=33609a3bc45bb407f0b26816158405b8';
+            $result = file_get_contents($url);
+            $result = json_decode($result, true);
+            $access_token = $result['access_token'];
+            //缓存
+            Cache::set('access_token', $access_token, 7000);
+        }
+        if (!$access_token) {
+            $this->error('参数缺失');
+        }
+
+//        $data['scene'] = 'id='.$id.'&code='.$this->auth->invite_no;
+        $data['scene'] = 'id=AVwvR&code='.$this->auth->invite_no;
+//        $data['page'] = 'pages/home/detail';
+        $data['page'] = 'pages/product/product';
+
+        $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token;
+        $ch = curl_init($url);
+        $timeout = 6000;
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_HEADER, 0);
+        curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
+        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
+        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
+        $ret = curl_exec($ch);
+        curl_close($ch);
+
+        if (is_array($ret)) {
+            return '';
+        }
+
+        $secretId = "AKIDhDTSBdoTs0rS4bx3rQijSu61f3B2cv3y"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
+        $secretKey = "f3A1btufAOL2SbT4ORDiwtZy7yYooY1D"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
+        $region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
+        $cosClient = new Client(
+            array(
+                'region' => $region,
+                'schema' => 'https', //协议头部,默认为http
+                'credentials'=> array(
+                    'secretId'  => $secretId ,
+                    'secretKey' => $secretKey)));
+//        $local_path = "/Users/xxx/Desktop/exampleobject.txt"; //保存到用户本地路径
+        $path = "qrcode/";     // 二维码文件流存放位置
+        $fileName = time() . rand(10000,99999) . ".png";
+        $result = $cosClient->putObject(array(
+            'Bucket' => 'examplebucket-1250000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
+            'Key' => $path . $fileName,//'exampleobject',
+            'Body' => $ret,//fopen($local_path, 'rb'),
+        ));
+        // 请求成功
+        p($result);
+
+
+//        //上传到阿里云oss
+//        require_once './Plugins/Aliyun/aliyun-oss-php-sdk-2.3.0/autoload.php';
+//        require_once './Plugins/Aliyun/aliyun-oss-php-sdk-2.3.0/src/OSS/OssClient.php';
+//        $config = C('ALIOSS_CONFIG');
+//
+//        $oss = new \OSS\OssClient($config['KEY_ID'], $config['KEY_SECRET'], $config['END_POINT']);
+//
+//        $path = "shopqrcode/";     // 二维码文件流存放位置
+//        $fileName = time() . rand(10000,99999) . ".png";
+//
+//        // 上传到oss
+//        $result = $oss->putObject($config['BUCKET'], $path . $fileName, $ret);
+//
+//        // 获取图片url地址
+//        $oss_url = json_decode(json_encode($result), true);
+//
+//        return $oss_url['oss-request-url'];
+    }
+
 }