获取小程序链接

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");
    }
相关推荐
HERR_QQ5 小时前
【unify】unify的微信小程序开发学习 (to be continued)
学习·微信小程序·小程序
racerun13 小时前
小程序导航设置更多内容的实现方法
小程序
说私域13 小时前
基于开源AI智能名片链动2+1模式S2B2C商城小程序的超级文化符号构建路径研究
人工智能·小程序·开源
mg66813 小时前
微信小程序入门实例_____快速搭建一个快递查询小程序
微信小程序·小程序
The_era_achievs_hero18 小时前
微信小程序41~50
微信小程序·小程序
走,带你去玩1 天前
uniapp 微信小程序水印
微信小程序·小程序·uni-app
CC同学呀1 天前
从0到100:单位订餐统计小程序开发日记2025
小程序
666HZ6662 天前
微信小程序中scss、ts、wxml
微信小程序·小程序·scss
二十十十十十2 天前
微信点餐小程序—美食物
微信·小程序