• PHP获取小程序太阳码


    function getAccessToken()
        {
            $appId = "";
            $secretId = "";
            $accessUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
    
            $url = sprintf($accessUrl, $appId, $secretId);
            $result = $this->https_request($url);
            $Result = json_decode($result, true);
            return $Result['access_token'];
        }
    
    
    
        function getProductQrcode($product_id, $page, $scene)
        {
            $field = 'qrcode_image';
            $file_path = 'product_qrcode';
            $dir = ROOT_PATH . 'public/uploads/qr/mall_qrcode';
    
    
    
            $user_info = \app\admin\model\shihu\Product::get($product_id);
    
    
            if (!empty($user_info[$field])) {
                return $user_info[$field];
            }
    
    
            $res = $this->getAccessToken();
            $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=$res";
            $processData = [
                'page' => $page,
                'scene' => $scene//二维码携带的参数
            ];
    
    
            $qrData = json_encode($processData);
    
    
            $data = $this->https_request($url, $qrData);
    
    
            $tmp = json_decode($data, true);
    
    
            if ($tmp['errcode'] == 45009 || $tmp['errcode'] == 41030) {
                return (['code' => $tmp['errcode'], 'msg' => $tmp['errmsg']]);
            }
            $filename = $product_id . date('YmdHis') . rand(10000, 999999) . '.jpg';
    
    
            if (!is_dir($dir)) {
                @mkdir($dir, 0777, true);
            }
    
            $file = $dir . '/' . $filename;
            file_put_contents($file, $data);
    
            $retFile = '/uploads/qr/' . $file_path . '/' . $filename;
    
            $user_info->qrcode_image = $retFile;
    
            $user_info->save();
            return $retFile;
        }
    
    
        function https_request($url, $data = null)
        {
            if (function_exists('curl_init')) {
                $curl = curl_init();
                curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
                curl_setopt($curl, CURLOPT_URL, $url);
                curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
                curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
                curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
                curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
                if (!empty($data)) {
                    curl_setopt($curl, CURLOPT_POST, 1);
                    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
                }
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                $output = curl_exec($curl);
                curl_close($curl);
                return $output;
            } else {
                return false;
            }
        }
  • 相关阅读:
    Spring Security -- 添加图形验证码(转载)
    Spring Security -- 自定义用户认证(转载)
    pandas agg 后降低df表层
    判断是否有人跟踪车辆的方案
    格隆汇笔记-黄勇演讲
    Mac mysql 忘记root密码的解决方法
    sql 同步2个表中的一个字段数据
    Linux下配置用msmtp和mutt发邮件
    spark StructType的应用,用在处理mongoDB keyvalue
    Idea2018旗舰版破解方法
  • 原文地址:https://www.cnblogs.com/sisl/p/16409417.html
Copyright © 2020-2023  润新知