获取小程序链接

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 小时前
基于开源链动 2+1 模式 AI 智能名片 S2B2C 商城小程序的社群团购品牌命名策略研究
人工智能·小程序·开源·零售
源码_V_saaskw9 小时前
场馆预定系统小程序PHP+uniapp
微信小程序·小程序·uni-app·php
七月shi人9 小时前
用claude3.7,不到1天写了一个工具小程序(11个工具6个游戏)
前端·小程序·ai编程
ml130185288749 小时前
开发一个小程序需要多久时间?小程序软件开发周期
java·小程序·开源软件·软件需求
说私域10 小时前
基于开源 AI 大模型 AI 智能名片 S2B2C 商城小程序的京城首家无人智慧书店创新模式研究
人工智能·小程序·开源·零售
然后就去远行吧12 小时前
小程序API —— 57 拓展 - 增强 scroll-view
小程序
Fri_14 小时前
微信小程序 request 流式数据处理
微信小程序·小程序
低代码布道师18 小时前
加油站小程序实战教程08用户注册
低代码·小程序
软件开发1561788292319 小时前
B2B2C多用户商城系统:打造新零售电商生态的创新解决方案
小程序·零售
艾路菲尔19 小时前
uniapp小程序登录失效后操作失灵问题
小程序·uni-app