1.入口index.php,显示信息在redirect.php,后台配置写redirect.php。

2.index.php

$APPID="D14---0A3";
$redirect_uri='http://xxx.net/w/redirect.php';
$url="https://dopen.weimob.com/fuwu/b/oauth2/authorize?enter=wm&view=pc&response_type=code&scope=default&client_id=".$APPID."&redirect_uri=".$redirect_uri."&state={state}";
header("Location:".$url);

3.redirect.php

$appid = "D14C6--CEFF0A3"; 
$secret = "FBE16---ACC67"; 
$code = isset($_GET['code'])?$_GET['code']:'';//获取code
$redirect_uri="http://bls-logistics.net/w/redirect.php";
$get_token_url="https://dopen.weimob.com/fuwu/b/oauth2/token?code=".$code."&grant_type=authorization_code&client_id=".$appid."&client_secret=".$secret."&redirect_uri=".$redirect_uri;

//若post信息,格式如下
$data = '{"code":'.$code.',"client_id":'.$appid.',"client_secret":'.$secret.',"grant_type":"authorization_code"}';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$get_token_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);
if (curl_errno($ch)) {
echo "Errno".curl_error($ch);
}
 
curl_close($ch);
$json_obj =json_decode($tmpInfo,true);
//print_r($json_obj);
$access_token=$json_obj["access_token"];
echo $access_token;