const app = getApp()
Page({
data: {
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo'),
data:{}
},
onLoad:function(){
var t = this
wx.login({
complete: (res) => {
if(res.code){
wx.request({
data:{code:res.code},
url: 'https://www.lefakeji.com/api/user/getwxuserinfo',
success:(re)=>{
var data = re.data
wx.checkSession({
complete: (res) => {
console.log(res)
},
})
console.log(re)
t.setData({
data:data
})
}
})
}
},
})
},
joinVoIPChat:function(){
var t = this
wx.getSetting({
success:function(r){
if(r.authSetting['scope.record']){
var data = t.data.data
console.log(data.sign)
console.log(data.nonceStr)
console.log(data.timeStamp)
console.log(data.groupId)
wx.joinVoIPChat({
signature:data.sign,
nonceStr:data.nonceStr,
timeStamp:parseInt(data.timeStamp),
groupId:data.groupId,
complete:(re)=>{
console.log(re)
wx.showModal({
title: '提示',
content: re.errMsg,
success (res) {
if (res.confirm) {
console.log('用户点击确定')
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
})
}else{
wx.startRecord({
complete: (res) => {
wx.stopRecord({
complete: (res) => {},
})
},
})
}
}
})
return
wx.startRecord({
success: (res) => {
},
fail:(re)=>{
console.log(re)
}
})
}
})
function curl_get_https($url)
{
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true); // 从证书中检查SSL加密算法是否存在
$tmpInfo = curl_exec($curl); //返回api的json对象
//关闭URL请求
curl_close($curl);
return $tmpInfo; //返回json对象
}
$appid = "wxxxxxx";
$appsecret = "c32526c8af5be2eeaxxxsxxxxxx";
$code = input('code', '');
$getInfoUrl = "https://api.weixin.qq.com/sns/jscode2session?appid={$appid}&secret={$appsecret}&js_code={$code}&grant_type=authorization_code";
$info = curl_get_https($getInfoUrl);
$info = json_decode($info,true);
if(!$info['session_key'])
$this->ajax(202,'session_key errors');
$groupId = 'grop_ooo00_tests';
$nonceStr = 'fdjkhdkhghwei7887438==';
$timeStamp = time();
$data = [
'appid' => $appid,
'groupId' => $groupId,
'nonceStr' => $nonceStr,
'timeStamp' => $timeStamp
];
sort($data,5); //这里是个坑 php sort 的默认参数不会把数字进行字典排序 相关参数请自行查看php文档
$st = implode('',$data); //拼接成一个字符串
$signature = hash_hmac('sha256', $st,$info['session_key']); //通过 sha256 加密
signature:data.sign, nonceStr:data.nonceStr, timeStamp:parseInt(data.timeStamp), groupId:data.groupId, 请问这些参数是怎么获取的?
你好,请问groupId只要是唯一的就可以吗,还有就是timeStamp时间戳怎么取呢
问题已经解决
你好,麻烦具体描述问题流程,提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html