API:wx.joinVoIPChat,微信版本号:7.0.15,基础库:2.12.0,参数appid为小程序id号,groupId,timeStamp,nonceStr 开发者随机创建,根据签名算法:
str = [appId, groupId, nonceStr, timeStamp].sort().join('')
signature = hmac_sha256(str, sessionKey)生成signature,
但是接口返回签名失败:
是因为groupId,timestamp,nonceStr这几个参数后台自己创建的格式不对吗?还是确定sessionKey的问题呢?求大佬解答
建议自查下参数
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 加密
Dictionary<string, string> strParam = new Dictionary<string, string>();
TimeSpan ts = DateTime.Now - DateTime.Parse("1970-1-1");