获取小程序链接

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");
    }
相关推荐
说私域2 小时前
“开源AI智能名片链动2+1模式S2B2C商城小程序”在直播公屏引流中的应用与效果
人工智能·小程序·开源
!win !4 小时前
uni-app项目支付宝端Input不受控
小程序·uni-app·支付宝小程序
毕设源码-钟学长5 小时前
【开题答辩全过程】以 “旧书驿站”微信小程序的设计与开发为例,包含答辩的问题和答案
微信小程序·小程序
毕设源码-赖学姐1 天前
【开题答辩全过程】以 “饭否”食材搭配指南小程序的设计与实现为例,包含答辩的问题和答案
小程序
nodcloud1 天前
点可云进销存商城如何部署在微信小程序
微信小程序·小程序
老华带你飞1 天前
畅阅读小程序|畅阅读系统|基于java的畅阅读系统小程序设计与实现(源码+数据库+文档)
java·数据库·vue.js·spring boot·小程序·毕设·畅阅读系统小程序
老华带你飞2 天前
租房平台|租房管理平台小程序系统|基于java的租房系统 设计与实现(源码+数据库+文档)
java·数据库·小程序·vue·论文·毕设·租房系统管理平台
项目題供诗2 天前
微信小程序开发教程(八)
微信小程序·小程序
00后程序员张2 天前
iOS App 混淆与资源保护:iOS配置文件加密、ipa文件安全、代码与多媒体资源防护全流程指南
android·安全·ios·小程序·uni-app·cocoa·iphone
低代码布道师2 天前
少儿舞蹈小程序(12)作品列表查询搭建
低代码·小程序