搜尋

首頁  >  問答  >  主體

依照影片上出現 40029 怎麼解決啊,都是PHP 下載sdk 改的哪裡code 用了兩次嗎

public function GetOpenid()

{

//透過code取得openid

if (!isset($_GET['code'])){

//觸發微信回傳碼

$baseUrl = urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING ' ]);

$url = $this->_CreateOauthUrlForCode($baseUrl);

標頭("位置:$url");

exit();

} else {

# //取得code碼,以獲得openid

    $code = $_GET['code'];

$openid = $this->getOpenidFromMp($code);

return $openid;

# }

}

## */

私有函數__CreateOauthUrlForOpenid($code)

{

$config = new WxPayConfig();

$urlObj["appid"] = $config- > GetAppId();

$urlObj["secret"] = $config->GetAppSecret();

$urlObj["js_code"] = $code;

$ urlObj["grant_type"] = "authorization_code";

$bizString = $this->ToUrlParams($urlObj);

# return "https://api.weixin. qq.com/ sns/jscode2session?".$bizString;

//回傳"https://api.weixin.qq.com/sns/oauth2/access_token?".$bizString;

}

公共函數GetOpenidFromMp($code)

{

# $url = $this->__CreateOauthUrlForOpenid($code);


//初始化curl


$ch = curl_init();

$curlVersion = curl_version();

$config = new WxPayConfig();

$ua = "WXPaySDK/3.0.9 (".PHP_OS.") PHP/".PHP_VERSION." CURL/".$curlVersion['版本']." "

. $config->GetMerchantId();


//設定逾時

curl_setopt($ch, CURLOPT_TIMEOUT, $this-> ;curl_timeout);

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($ch, CURLOPT_USERAGENT, $ua);

curl_setopt($ch, CURLOPT_HEADER, FALSE);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TR# );

# $proxyHost = "0.0.0.0";

# $proxyPort = 0;

$config->GetProxy( $proxyHost, $proxyPort);

if($proxyHost != "0.0.0.0" && $proxyPort != 0){

curl_setopt($ch,CURLOPT_PROXY, $proxyHost);

# curl_setopt($ ch,CURLOPT_PROXYPORT, $proxyPort);

}

//執行curl,結果以jason形式傳回

$res = curl_exec( $ch);

curl_close($ch);

// 取出openid

$data = json_decode($res,true);

$ this->data = $data;

$openid = $data['openid'];

return $openid;

}


####################################################
长路漫漫,代码作伴长路漫漫,代码作伴2274 天前1983

全部回覆(0)我來回復

無回覆
  • 取消回覆