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_setopt($ch, CURLOPT_USERAGENT, $ua);curl_setopt($ch, CURLOPT_HEADER, FALSE);curl_setopt($ch, CURLOPT_RETURNTRANSFER, TR# );
# $proxyHost = "0.0.0.0";