微信公众号h5登录
public function getCode()
{
$order_id = '95896766';
$config = config('wechat.official_account');
$appid = $config['app_id'];
$redirect_uri = urlencode('https://bianque-h5-test.quansuwangluo.com/api/card/getuserinfo?order_id=' . $order_id);
$scope = 'snsapi_userinfo'; // 如果需要用户信息,使用snsapi_userinfo
$state = 'STATE'; // 自定义状态值
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=$scope&state=$state#wechat_redirect";
header("Location:{$url}");
exit;
}
public function getuserinfo($code, $order_id)
{
$config = config('wechat.official_account');
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $config['app_id']
. "&secret=" . $config['secret'] . "&code=" . $code . "&grant_type=authorization_code";
$jsonResult = file_get_contents($url);
$resultArray = json_decode($jsonResult, true);
echo '<pre>';
print_r($resultArray);
print_r($order_id);
exit;
$access_token = $resultArray["access_token"];
}