From 6e0d4778d0bc799ecc5898228a54799d255254ef Mon Sep 17 00:00:00 2001 From: wang hou sheng <76928547+wanghousheng@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:13:50 +0800 Subject: [PATCH] 1 --- app/common/library/wxserver/Server.php | 31 +++++++++++++------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/app/common/library/wxserver/Server.php b/app/common/library/wxserver/Server.php index c207f788..90fc88c9 100644 --- a/app/common/library/wxserver/Server.php +++ b/app/common/library/wxserver/Server.php @@ -487,11 +487,17 @@ class Server } } - public function getPrivacySetting($appid) + /** + * @notes:设置隐私 + * @param $appid + * @return bool + * @author: wanghousheng + */ + public function getPrivacySetting($appid): bool { $token = $this->authorizerAccessToken($appid); if ($token) { - $url = "https://api.weixin.qq.com/cgi-bin/component/getprivacysetting?access_token=$token"; + $url = "https://api.weixin.qq.com/cgi-bin/component/setprivacysetting?access_token=$token"; $setting_list = [ ['privacy_key' => 'PhoneNumber', 'privacy_text' => '用于用户一键登录'], ['privacy_key' => 'Location', 'privacy_text' => '用于用户选择自提点'], @@ -505,21 +511,12 @@ class Server $data['owner_setting']['contact_qq'] = '527264601'; $data['owner_setting']['notice_method'] = '公告'; $result = $this->curlPost($url, json_encode($data)); - return json_decode($result, true); - } - return []; - } - - public function setPrivacySetting($appid) - { - $token = $this->authorizerAccessToken($appid); - if ($token) { - $url = "https://api.weixin.qq.com/cgi-bin/component/setprivacysetting?access_token=$token"; - $data['privacy_ver'] = 1; - $result = $this->curlPost($url, json_encode($data)); - return json_decode($result, true); + $result = json_decode($result, true); + if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') { + return true; + } } - return []; + return false; } public function apiText($authorization_code, $touser) @@ -589,6 +586,8 @@ class Server $model->insertGetId($insert_data); //设置域名信息 $this->setDomain($insert_data['appid'], $domain); + //设置隐私 + $this->getPrivacySetting($insert_data['appid']); } } }