获取openid [微信小程序]
public function wxapi(){ $data=$this->requestdata(); if(!$data['code']) exit(json_encode(array('status'=>-1,'msg'=>'参数异常'))); $paymentPlugin = M('Plugin')->where("code='weixin' and type = 'payment' ")->find(); // 找到微信支付插件的配置 $config_value = unserialize($paymentPlugin['config_value']); // 配置反序列化 $appid = $config_value['appid']; // * APPID:绑定支付的APPID(必须配置,开户邮件中可查看) $mchid = $config_value['mchid']; // * MCHID:商户号(必须配置,开户邮件中可查看) $key = $config_value['key']; // KEY:商户支付密钥,参考开户邮件设置(必须配置,登录商户平台自行设置) $appsecret = $config_value['appsecret']; // 公众帐号secert(仅JSAPI支付的时候需要配置), $url = "https://api.weixin.qq.com/sns/jscode2session?appid=$appid&secret=$appsecret&grant_type=authorization_code&js_code="; $json=file_get_contents($url.$data["code"]); //$res = json_decode($res, true); $jsoarray = json_decode($json, true); exit(json_encode(array('status'=>1,'msg'=>'访问成功',"result"=>$jsoarray))); }
code 微信小程序 wx.login获取到的