post请求验证提交的微信名称

This commit is contained in:
wangxiaowei 2024-09-25 11:20:07 +08:00
parent 2339f2b0ab
commit b5ed55e27f

@ -59,26 +59,31 @@ class User extends Api
} else {
$userAuth = Db::name('user_auth')->where('user_id', $this->user_id)->find();
if($userAuth) {
$postData = [
$data = [
'content' => $post['value'],
'version' => 2,
'scene' => 1,
'openid' => $userAuth['openid']
];
$ch = curl_init(); // 初始化curl
$url = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=' . $response['access_token']; // 目标URL
$data_json = json_encode($data); // 将数据编码为JSON
curl_setopt($ch, CURLOPT_URL, 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=' . $response['access_token']); // 抓取指定网页
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 要求结果为字符串并输出到屏幕上
curl_setopt($ch, CURLOPT_POST, 1); // post请求方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); // post变量
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
));
$ch = curl_init($url); // 初始化cURL会话
curl_setopt($ch, CURLOPT_POST, true); // 设置为POST请求
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json); // 设置POST数据
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); // 设置头部信息
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 将响应作为字符串返回
$output = curl_exec($ch);
curl_close($ch);
dump($output);die;
$response = curl_exec($ch); // 执行cURL请求
curl_close($ch); // 关闭cURL会话
$res = json_decode($response, true);
if (!empty($res['errcode'])) {
return JsonServer::error('信息获取错误');
} else if ($res['result']['label'] != 100) {
return JsonServer::error('您的昵称含有非法字符,请重新设置');
}
}
return JsonServer::error('暂无授权信息');