获取小程序链接

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");
    }
相关推荐
2501_9159184112 小时前
iOS 开发全流程实战 基于 uni-app 的 iOS 应用开发、打包、测试与上架流程详解
android·ios·小程序·https·uni-app·iphone·webview
黑马源码库miui5208613 小时前
JAVA同城打车小程序APP打车顺风车滴滴车跑腿源码微信小程序打车源码
java·微信·微信小程序·小程序·uni-app
一口十个小甜虾13 小时前
微信小程序体验版,当打开调试模式正常访问,关闭之后无法访问
微信小程序·小程序
悟空码字13 小时前
微信开放平台第三方平台,可以管理多个微信小程序
微信·小程序·开放平台
じòぴé南冸じょうげん13 小时前
微信小程序如何进行分包处理?
前端·小程序
说私域15 小时前
基于开源AI大模型AI智能名片S2B2C商城小程序的参与感构建研究
人工智能·小程序·开源
毕设源码-邱学长1 天前
【开题答辩全过程】以 基于微信小程序的宠物领养系统为例,包含答辩的问题和答案
微信小程序·小程序·宠物
canglingyue1 天前
微信小程序日历事件添加实现
微信小程序·小程序
毕设源码-邱学长2 天前
【开题答辩全过程】以 基于微信小程序校园综合服务平台的设计与实现为例,包含答辩的问题和答案
微信小程序·小程序
從南走到北2 天前
JAVA同城打车小程序APP打车顺风车滴滴车跑腿源码微信小程序打车源码
java·开发语言·微信·微信小程序·小程序