From b5ed55e27fa92acd57c7af1d14d63f628bd9cbaf Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Wed, 25 Sep 2024 11:20:07 +0800 Subject: [PATCH] =?UTF-8?q?post=E8=AF=B7=E6=B1=82=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=9A=84=E5=BE=AE=E4=BF=A1=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/User.php | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/app/api/controller/User.php b/app/api/controller/User.php index 95e14b05..0a026fdf 100755 --- a/app/api/controller/User.php +++ b/app/api/controller/User.php @@ -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('暂无授权信息');