var API_URL = "自己的服务器地址";
Page({
onLoad: function () {
console.log("iv");
wx.login({//login流程
success: function (res) {//登录成功
if (res.code) {
var code = res.code;
wx.getUserInfo({//getUserInfo流程
success: function (res2) {//获取userinfo成功
console.log(res2);
var encryptedData = encodeURIComponent(res2.encryptedData);//一定要把加密串转成URI编码
var iv = res2.iv;
//请求自己的服务器
Login(code,encryptedData,iv);
}
})
} else {
console.log('获取用户登录态失败!' + res.errMsg)
}
}
});
}
})
function Login(code,encryptedData,iv){ console.log('code='+code+'&encryptedData='+encryptedData+'&iv='+iv);
//创建一个dialog
wx.showToast({
title: '正在登录...',
icon: 'loading',
duration: 10000
});
//请求服务器
wx.request({
url: API_URL,
data: {
code:code,
encryptedData:encryptedData,
iv:iv
},
method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
header: {
'content-type': 'application/json'
}, // 设置请求的 header
success: function (res) {
// success
wx.hideToast();
console.log('服务器返回'+res.data);
},
fail: function () {
// fail
// wx.hideToast();
},
complete: function () {
// complete
}
})
}
/**
* 登录
*
* @return Response
*/
public function weixinlogin( $user_id=null )
{
global $App_Error_Conf,$Gift_Ids,$Server_Http_Path,$Is_Local,$Test_User,$Good_Vcode,$WeiXin_Xd_Conf;
$validator_result = input_validator(array('code','iv','encryptedData'));
if(!empty($validator_result)){
return response($validator_result);
}
$js_code = $_REQUEST['code'];
$encryptedData = $_REQUEST['encryptedData'];
$iv = $_REQUEST['iv'];
$appid = $WeiXin_Xd_Conf['appid'];
$secret = $WeiXin_Xd_Conf['secret'];
$grant_type = $WeiXin_Xd_Conf['grant_type'];
//从微信获取session_key
$user_info_url = $WeiXin_Xd_Conf['code2session_url'];
$user_info_url = sprintf("%s?appid=%s&secret=%s&js_code=%s&grant_type=%",$user_info_url,$appid,$secret,$js_code,$grant_type);
$weixin_user_data = json_decode(get_url($user_info_url));
$session_key = $weixin_user_data->session_key;
//解密数据
$data = '';
$wxBizDataCrypt = new WXBizDataCrypt($appid, $session_key);
$errCode=$wxBizDataCrypt>decryptData($appid,$session_key,$encryptedData, $iv, $data );
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有