获取小程序链接

php 复制代码
 /**
     * 小程序微信AccessToken
     * @param array $data
     */
   public function getAccessToken($appid, $appsecret)
    {
        $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$appsecret}";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $data = curl_exec($ch);
        curl_close($ch);
        $result = json_decode($data, true);
        if (isset($result['access_token'])) {
            return $result['access_token'];
        } else {
            return false;
        }
    }
    /**
     * 小程序微信AccessToken
     * @param array $data
     */
    public function getwxurllink(){
   
     
    // 		$OrderID = intval($_REQUEST['OrderID']);
       
        // 小程序码生成 API 地址
        $url = 'https://api.weixin.qq.com/wxa/generate_urllink?access_token=';
      
        	$XcsAppID = $GLOBALS['Config']['XCX_APP_ID'];
		$XcxAppSecret = $GLOBALS['Config']['XCX_APP_SECRET'];
		
		if( empty($XcsAppID) || empty($XcxAppSecret) ){
			$this->ApiReturn(null, L('AppIDAppSecretNotConfig'), 0, API_FORMAT);
		}
		
		$appid =$XcsAppID;
          
        $appsecret =$XcxAppSecret;
        $access_token = $this->getAccessToken($appid, $appsecret);

        if (!$access_token) { 
            // 获取 access_token 失败,处理错误 
          
            	$this->ApiReturn(false, "access_token处理错误", 0, API_FORMAT);
        }
        $data = array(
            'query' => 'from_id='.$this->user->id.",from_type=".$from_type,//参数
            'path' => '/pages/publishHomework/publishHomework',
            "is_expire"=>true,
            "expire_type"=>1,
            "expire_interval"=>1,
            "env_version"=> "release",
        );
      
        /*
 
        // $data = array(
        //     'scene' => 'from_id='.$this->user->id.",from_type=".$from_type,
        //     'page' => 'pages/tabbar/tabbar_1/tabbar_1',
        //     'width' => 430,
        //     "check_path"=>false,
        //     'auto_color' => false,
        //     'is_hyaline' => false
        // );
        */
        // 发送 POST 请求
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url . $access_token);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         $response= curl_exec($ch);
        curl_close($ch);
        $responsedata=json_decode($response,true);
        if($responsedata["errcode"]==0){
            
    	$this->ApiReturn(array('Data'=>$response["urlLink"]), '', 1, API_FORMAT);
        }else{
            
            	$this->ApiReturn(false, "第三方参数错误", 0, API_FORMAT);
        }
        // return $this->jsonResponse(200,'成功',"http://ktadmin.damili.cn/qrcode.png");
    }
相关推荐
正小安4 小时前
如何在微信小程序中实现分包加载和预下载
前端·微信小程序·小程序
说私域4 小时前
基于定制开发与2+1链动模式的商城小程序搭建策略
大数据·小程序
工业互联网专业12 小时前
毕业设计选题:基于ssm+vue+uniapp的校园水电费管理小程序
vue.js·小程序·uni-app·毕业设计·ssm·源码·课程设计
说私域15 小时前
社群团购中的用户黏性价值:以开源小程序多商户AI智能名片商城源码为例
人工智能·小程序
迷雾yx19 小时前
开发微信小程序 基础02
微信小程序·小程序
迷雾yx19 小时前
开发微信小程序 基础03
微信小程序·小程序
说私域20 小时前
地理定位营销与开源AI智能名片O2O商城小程序的融合与发展
人工智能·小程序
技术闲聊DD2 天前
小程序原生-利用setData()对不同类型的数据进行增删改
小程序
康康爹2 天前
uniapp 小程序,登录上传头像昵称页面处理步骤
小程序·uni-app
小雨cc5566ru2 天前
小程序 uniapp+Android+hbuilderx体育场地预约管理系统的设计与实现
android·小程序·uni-app