위챗 브라우저 페이지 권한 수여 취득 사용자 openid 위챗 브라우저 지불

2505 단어 기초 지식
###   
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_get($url);
    return $ass_key;
}
//    
function curl_get($url) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($curl);
    $err = curl_error($curl);
    curl_close($curl);
    return json_decode($data,1);//     json  
}
```
###   
```
//                    

data.timeStamp = String(data.timeStamp);
WeixinJSBridge.invoke('getBrandWCPayRequest', {
    'appId': data.appid ? data.appid : data.appId,
    'timeStamp': data.timeStamp,
    'nonceStr': data.nonceStr,
    'package': data.package,
    'signType': data.signType,
    'paySign': data.paySign,
}, function(res) {
    if(res.err_msg == 'get_brand_wcpay_request:ok') {
//                                    location.href = "{php echo app_url('pay/cash')}&orderno="+orderno+"&paytype="+paytype+"&done=1";
        alert("    ");
        location.reload();
    } else {
        /*$.post("{php echo app_url('pay/paytype')}",{orderno:orderno,remark:remark,othername:othername,op:"ajax",checkpay:"8"},function(m){
         $.toast("     ");
         },"json");*/
        alert("     1");
    }
});

```

좋은 웹페이지 즐겨찾기