/** * 小程序微信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"); }
发表评论 取消回复