### 配置
1. appid
2. appsecret
3. merchid
4. apikey
5. 微信公众号,接口权限,网页授权域名填写
### 获取code
```
function getWxCode($url){
$appid = "";
$appsecret = "";
$domain = input('server.REQUEST_SCHEME'). '://' . input('server.SERVER_NAME');
//url填写可当前访问url
$redirect_url = $domain."/".$url;
$redirect_url = urlencode($redirect_url);
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri=".$redirect_url."&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
// dump($url);exit;
// $result = curl_get($url);
// return $result;
return $url;
}
//引导用户访问此url
```
### 根据code获取openid
```
$param =request()->param();
$code = $param['code'];
function returnAsskey($code)
{
$appid = “”;
$appsecret = "";
$url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$appsecret.'&code='.$code.'&grant_type=authorization_code';
$ass_key = curl
微信浏览器网页授权获取用户openid 微信浏览器支付
最新推荐文章于 2025-07-14 15:11:19 发布