1、授权拿到openid,并到到支付页面
2、前端调起后端返回的参数
3、支付,支付时需要openid请求统一接口
public function wxInfo()
{
$appid = 'wxfxxxx'; //服务号
$form = $_GET['user_id'];
//判断登录
if(!$form){
$this->error('请先登录');
}
if(session('user_info')){
$user_id = $form;
$sql = "select *from user where id = $user_id";
$user_other_info = M()->query($sql)[0];
$this->assign('wx_info',session('user_info'));
$this->assign('user_other_info',$user_other_info);
$this->assign('jsApiParameters','');
$this->display('wap/User/xxxx');
}else{
header('location:https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$appid.'&redirect_uri=http://www.xxxx.com/WapPay/varInfo&response_type=code&scope=snsapi_userinfo&state='.$form.'#wechat_redirect');
}
}
public function varInfo()
{
if(!session('user_info')){
$code = $_GET['code'];
$state = $_GET['state'];
$appid = 'xxxxxxxxxxx';
$appsecret = 'xxxxxxxxxxxxxx';
if (empty($code)) $this->error('授权失败');
$token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid . '&secret=' . $appsecret . '&code=' . $code . '&grant_type=authorization_code';
$token = json_decode(file_get_contents($token_url));
if (isset($token->errcode)) {
echo '<h1>错误:<