按照视频上出现 40029 要怎么解决啊,都是PHP 下载sdk 改的哪里code 用了两次吗
长路漫漫,代码作伴
长路漫漫,代码作伴 2018-09-05 11:14:15
0
0
1975

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, TRUE );


## $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;

}


长路漫漫,代码作伴
长路漫漫,代码作伴

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板