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獲取到的php