(2)网页授权获取用户基本信息
(二)网页授权获取用户基本信息
在公众号的配置过程中,许多开发者会在菜单中加入HTML5页面,有时在页面内需要访问页面的用户信息,此时就需要网页授权获取用户基本信息
PS:本博文所阐述的微信开发基于Yii2.0框架
1、设置授权回调域名:开发 ---> 接口权限
找到“网页授权获取用户基本信息”,点击后面对应的“修改”,在弹框响应位置填写授权回调域名即可,此处的域名不需要加http:// (关于网页授权回调域名的说明详情可参考公众平台开发者文档)
2、获取授权
关于OAuth2.0博主参考的是方倍工作室的博文http://www.cnblogs.com/txw1958/p/weixin71-oauth20.html(PS:方倍是一个微信开发大神,其中的微信开发内容还是比较详细的,推荐参考),其中详细剖析了微信官方文档的相关内容,也提供了获取授权的更详细思路和方案。
实际上,获取用户信息的关键在于获取用户的openid。博主想要实现用户点击公众号菜单打开页面即可自动授权,从而针对该用户进行数据库操作,于是有下面两种方式:
(1)利用自定义菜单请求授权页面
自定义菜单后面会单独写一篇博文,在这里先简述一下通过自定义菜单进行授权,该方法需要高级接口权限,且局限于关注公众号的用户直接从菜单进入页面。
1 |
|
需要授权的view直接在url处填写微信提供的授权请求地址,其中:
- appid:填写微信公众平台基本配置中的AppID;
- redirect_uri:填写授权完成后跳转的页面地址,即自己的html5页面;
- state:跳转至回调页面所带参数;
-
response_type:网页授权的两种scope,微信官方文档中说明如下:
1
1<span style=
"color: #000000;"
>、以snsapi_base为scope发起的网页授权,是用来获取进入页面的用户的openid的,并且是静默授权并自动跳转到回调页的。用户感知的就是直接进入了回调页(往往是业务页面)</span>2、以snsapi_userinfo为scope发起的网页授权,是用来获取用户的基本信息的。但这种授权需要用户手动同意,并且由于用户同意过,所以无须关注,就可在授权后获取该用户的基本信息。
登入後複製按照此方法点击“商城”即可接收到返回的openid,继而进行下一步用户信息的获取。
(2)利用JS自动请求授权页面
这个方法相对而言比较笨拙,步骤略复杂,但目前能解决需求还没有研究简化方法,且由于页面的跳转多数情况下访问页面的时间会增加,但相比于前一个方法,该方法可以获取到非关注用户的基本信息。有些程序可能涉及到页面分享,程序没有强制关注但其他用户通过分享直接进入页面也需要记录用户信息,此时可以考虑该方法。(微信开发相关的代码博主封装成工具类调用,这里先贴用到的部分,以后整理完成会全部贴出来并附下载链接)
该方法的思路为:js请求链接获取code ---> 利用code换取openid ---> 得到用户基本信息
a. 编辑配置
为了方便把用到的一些微信参数单独写入一个类,方便修改添加及调用
1
<span style=
"color: #008080;"
> 1</span> <span style=
"color: #000000;"
>php</span><span style=
"color: #008080;"
> 2</span> <span style=
"color: #000000;"
>
namespace
common\tools\wechat;</span><span style=
"color: #008080;"
> 3</span> <span style=
"color: #008080;"
> 4</span> <span style=
"color: #008000;"
>
/*</span><span style="color: #008000;">*</span><span style="color: #008080;"> 5</span> <span style="color: #008000;"> * 微信请求相关配置类库</span><span style="color: #008080;"> 6</span> <span style="color: #008000;">*/
</span><span style=
"color: #008080;"
> 7</span> <span style=
"color: #0000ff;"
>
class
</span><span style=
"color: #000000;"
> ConfigTool {</span><span style=
"color: #008080;"
> 8</span> <span style=
"color: #008080;"
> 9</span> <span style=
"color: #008000;"
>
/*</span><span style="color: #008000;">*</span><span style="color: #008080;">10</span> <span style="color: #008000;"> * 微信配置参数</span><span style="color: #008080;">11</span> <span style="color: #008000;"> * @return array 配置参数</span><span style="color: #008080;">12</span> <span style="color: #008000;">*/
</span><span style=
"color: #008080;"
>13</span> <span style=
"color: #0000ff;"
>
public
</span> <span style=
"color: #0000ff;"
>
function
</span><span style=
"color: #000000;"
> setConfig() {</span><span style=
"color: #008080;"
>14</span> <span style=
"color: #008080;"
>15</span> <span style=
"color: #008000;"
>
//</span><span style="color: #008000;"> 用于验证微信接口配置信息的Token,可以任意填写</span><span style="color: #008080;">16</span> <span style="color: #800080;">$config</span>['token'] = '自己的token'<span style="color: #000000;">;</span><span style="color: #008080;">17</span> <span style="color: #008080;">18</span> <span style="color: #008000;">//</span><span style="color: #008000;"> appID</span><span style="color: #008080;">19</span> <span style="color: #800080;">$config</span>['appid'] = '自己的appid'<span style="color: #000000;">;</span><span style="color: #008080;">20</span> <span style="color: #008080;">21</span> <span style="color: #008000;">//</span><span style="color: #008000;"> appSecret</span><span style="color: #008080;">22</span> <span style="color: #800080;">$config</span>['secret'] = '自己的secret'<span style="color: #000000;">;</span><span style="color: #008080;">23</span> <span style="color: #008080;">24</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 回调链接地址</span><span style="color: #008080;">25</span> <span style="color: #800080;">$config</span>['redirect_uri'] = 'http://tx.heivr.com/index.php?'<span style="color: #000000;">;</span><span style="color: #008080;">26</span> <span style="color: #008080;">27</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 是否以 HTTPS 安全协议访问接口</span><span style="color: #008080;">28</span> <span style="color: #800080;">$config</span>['https_request'] = <span style="color: #0000ff;">false</span><span style="color: #000000;">;</span><span style="color: #008080;">29</span> <span style="color: #008080;">30</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 授权作用域,snsapi_base (不弹出授权页面,直接跳转,只能获取用户openid),</span><span style="color: #008080;">31</span> <span style="color: #008000;"> // snsapi_userinfo (弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,</span><span style="color: #008080;">32</span> <span style="color: #008000;"> // 即使在未关注的情况下,只要用户授权,也能获取其信息)</span><span style="color: #008080;">33</span> <span style="color: #800080;">$config</span>['scope'] = 'snsapi_userinfo'<span style="color: #000000;">;</span><span style="color: #008080;">34</span> <span style="color: #008080;">35</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 语言</span><span style="color: #008080;">36</span> <span style="color: #800080;">$config</span>['lang'] = 'zh_CN'; <span style="color: #008000;">//</span><span style="color: #008000;"> zh_CN 简体,zh_TW 繁体,en 英语</span><span style="color: #008080;">37</span> <span style="color: #008080;">38</span> <span style="color: #008000;"> // 微信公众账户授权地址</span><span style="color: #008080;">39</span> <span style="color: #800080;">$config</span>['mp_authorize_url'] = 'https://api.weixin.qq.com/cgi-bin/token'<span style="color: #000000;">;</span><span style="color: #008080;">40</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 微信公众账户js临时票据地址</span><span style="color: #008080;">41</span> <span style="color: #800080;">$config</span>['jsapi_ticket_url'] = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket'<span style="color: #000000;">;</span><span style="color: #008080;">42</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 授权地址</span><span style="color: #008080;">43</span> <span style="color: #800080;">$config</span>['authorize_url'] = 'https://open.weixin.qq.com/connect/oauth2/authorize'<span style="color: #000000;">;</span><span style="color: #008080;">44</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 获取access token 的地址</span><span style="color: #008080;">45</span> <span style="color: #800080;">$config</span>['access_token_url'] = 'https://api.weixin.qq.com/sns/oauth2/access_token'<span style="color: #000000;">;</span><span style="color: #008080;">46</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 刷新 token 的地址</span><span style="color: #008080;">47</span> <span style="color: #800080;">$config</span>['refresh_token_url'] = 'https://api.weixin.qq.com/sns/oauth2/refresh_token'<span style="color: #000000;">;</span><span style="color: #008080;">48</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 获取用户信息地址</span><span style="color: #008080;">49</span> <span style="color: #800080;">$config</span>['userinfo_url'] = 'https://api.weixin.qq.com/sns/userinfo'<span style="color: #000000;">;</span><span style="color: #008080;">50</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 验证access token</span><span style="color: #008080;">51</span> <span style="color: #800080;">$config</span>['valid_token_url'] = 'https://api.weixin.qq.com/sns/auth'<span style="color: #000000;">;</span><span style="color: #008080;">52</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 上传临时素材地址</span><span style="color: #008080;">53</span> <span style="color: #800080;">$config</span>['media_temp_upload_url'] = 'https://api.weixin.qq.com/cgi-bin/media/upload?'<span style="color: #000000;">;</span><span style="color: #008080;">54</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 上传永久素材地址</span><span style="color: #008080;">55</span> <span style="color: #800080;">$config</span>['media_forever_upload_url'] = 'https://api.weixin.qq.com/cgi-bin/material/add_material?'<span style="color: #000000;">;</span><span style="color: #008080;">56</span> <span style="color: #008080;">57</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">$config</span><span style="color: #000000;">;</span><span style="color: #008080;">58</span> <span style="color: #008080;">59</span> <span style="color: #000000;"> }</span><span style="color: #008080;">60</span> }
登入後複製b. https请求工具
1
<span style=
"color: #008080;"
> 1</span> <span style=
"color: #000000;"
>php</span><span style=
"color: #008080;"
> 2</span> <span style=
"color: #000000;"
>
namespace
common\tools;</span><span style=
"color: #008080;"
> 3</span> <span style=
"color: #008080;"
> 4</span> <span style=
"color: #008000;"
>
/*</span><span style="color: #008000;">*</span><span style="color: #008080;"> 5</span> <span style="color: #008000;"> * https请求相关类库</span><span style="color: #008080;"> 6</span> <span style="color: #008000;">*/
</span><span style=
"color: #008080;"
> 7</span> <span style=
"color: #0000ff;"
>
class
</span><span style=
"color: #000000;"
> HttpsTool {</span><span style=
"color: #008080;"
> 8</span> <span style=
"color: #008080;"
> 9</span> <span style=
"color: #0000ff;"
>
const
</span> TIMEOUT = 5; <span style=
"color: #008000;"
>
//</span><span style="color: #008000;"> 设置超时时间</span><span style="color: #008080;">10</span> <span style="color: #008080;">11</span> <span style="color: #0000ff;">private</span> <span style="color: #800080;">$ch</span>; <span style="color: #008000;">//</span><span style="color: #008000;"> curl对象</span><span style="color: #008080;">12</span> <span style="color: #008080;">13</span> <span style="color: #008000;">/*</span><span style="color: #008000;">*</span><span style="color: #008080;">14</span> <span style="color: #008000;"> * 发送curl请求,并获取请求结果</span><span style="color: #008080;">15</span> <span style="color: #008000;"> * @param string 请求地址</span><span style="color: #008080;">16</span> <span style="color: #008000;"> * @param array 如果是post请求则需要传入请求参数</span><span style="color: #008080;">17</span> <span style="color: #008000;"> * @param string 请求方法,get 或者 post, 默认为get</span><span style="color: #008080;">18</span> <span style="color: #008000;"> * @param bool 是否以https协议请求</span><span style="color: #008080;">19</span> <span style="color: #008000;">*/</span><span style="color: #008080;">20</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> send_request(<span style="color: #800080;">$requests</span>, <span style="color: #800080;">$params</span> = <span style="color: #0000ff;">null</span>, <span style="color: #800080;">$method</span> = 'get', <span style="color: #800080;">$https</span> = <span style="color: #0000ff;">true</span><span style="color: #000000;">) {</span><span style="color: #008080;">21</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 以get方式提交</span><span style="color: #008080;">22</span> <span style="color: #0000ff;">if</span> (<span style="color: #800080;">$method</span> == 'get'<span style="color: #000000;">) {</span><span style="color: #008080;">23</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$params</span><span style="color: #000000;">){</span><span style="color: #008080;">24</span> <span style="color: #800080;">$request</span> = <span style="color: #800080;">$requests</span> . <span style="color: #800080;">$this</span>->create_url(<span style="color: #800080;">$params</span><span style="color: #000000;">);</span><span style="color: #008080;">25</span> }<span style="color: #0000ff;">else</span><span style="color: #000000;">{</span><span style="color: #008080;">26</span> <span style="color: #800080;">$request</span> = <span style="color: #800080;">$requests</span><span style="color: #000000;">;</span><span style="color: #008080;">27</span> <span style="color: #000000;"> }</span><span style="color: #008080;">28</span> }<span style="color: #0000ff;">else</span><span style="color: #000000;">{</span><span style="color: #008080;">29</span> <span style="color: #800080;">$request</span> = <span style="color: #800080;">$requests</span><span style="color: #000000;">;</span><span style="color: #008080;">30</span> <span style="color: #000000;"> }</span><span style="color: #008080;">31</span> <span style="color: #008080;">32</span> <span style="color: #800080;">$this</span>->ch = curl_init(<span style="color: #800080;">$request</span><span style="color: #000000;">);</span><span style="color: #008080;">33</span> curl_setopt(<span style="color: #800080;">$this</span>->ch, CURLOPT_RETURNTRANSFER, 1);<span style="color: #008000;">//</span><span style="color: #008000;"> 设置不显示结果,储存入变量</span><span style="color: #008080;">34</span> curl_setopt(<span style="color: #800080;">$this</span>->ch, CURLOPT_TIMEOUT, self::TIMEOUT); <span style="color: #008000;">//</span><span style="color: #008000;"> 设置超时限制防止死循环</span><span style="color: #008080;">35</span> <span style="color: #008080;">36</span> <span style="color: #008000;"> // 判断是否以https方式访问</span><span style="color: #008080;">37</span> <span style="color: #0000ff;">if</span> (<span style="color: #800080;">$https</span><span style="color: #000000;">) {</span><span style="color: #008080;">38</span> curl_setopt(<span style="color: #800080;">$this</span>->ch, CURLOPT_SSL_VERIFYPEER, 0); <span style="color: #008000;">//</span><span style="color: #008000;"> 对认证证书来源的检查</span><span style="color: #008080;">39</span> curl_setopt(<span style="color: #800080;">$this</span>->ch, CURLOPT_SSL_VERIFYHOST, 0); <span style="color: #008000;">//</span><span style="color: #008000;"> 从证书中检查SSL加密算法是否存在</span><span style="color: #008080;">40</span> <span style="color: #000000;"> }</span><span style="color: #008080;">41</span> <span style="color: #008080;">42</span> <span style="color: #0000ff;">if</span> (<span style="color: #800080;">$method</span> == 'post') { <span style="color: #008000;">//</span><span style="color: #008000;"> 以post方式提交</span><span style="color: #008080;">43</span> <span style="color: #008000;"> //curl_setopt($this->ch, CURLOPT_SAFE_UPLOAD, false); //php 5.6文件上传必加内容,5.4不需要</span><span style="color: #008080;">44</span> curl_setopt(<span style="color: #800080;">$this</span>->ch, CURLOPT_POST, 1); <span style="color: #008000;">//</span><span style="color: #008000;"> 发送一个常规的Post请求</span><span style="color: #008080;">45</span> curl_setopt(<span style="color: #800080;">$this</span>->ch, CURLOPT_POSTFIELDS, <span style="color: #800080;">$params</span>); <span style="color: #008000;">//</span><span style="color: #008000;"> Post提交的数据包</span><span style="color: #008080;">46</span> curl_setopt(<span style="color: #800080;">$this</span>->ch, CURLOPT_RETURNTRANSFER, 1<span style="color: #000000;">);</span><span style="color: #008080;">47</span> <span style="color: #000000;"> }</span><span style="color: #008080;">48</span> <span style="color: #008080;">49</span> <span style="color: #800080;">$tmpInfo</span> = curl_exec(<span style="color: #800080;">$this</span>->ch); <span style="color: #008000;">//</span><span style="color: #008000;"> 执行操作</span><span style="color: #008080;">50</span> <span style="color: #0000ff;">if</span> (curl_errno(<span style="color: #800080;">$this</span>-><span style="color: #000000;">ch)) {</span><span style="color: #008080;">51</span> <span style="color: #0000ff;">echo</span> 'Errno:'.curl_error(<span style="color: #800080;">$this</span>->ch);<span style="color: #008000;">//</span><span style="color: #008000;">捕抓异常</span><span style="color: #008080;">52</span> <span style="color: #000000;"> }</span><span style="color: #008080;">53</span> curl_close(<span style="color: #800080;">$this</span>->ch); <span style="color: #008000;">//</span><span style="color: #008000;"> 关闭CURL会话</span><span style="color: #008080;">54</span> <span style="color: #008000;"> //var_dump($tmpInfo);exit;</span><span style="color: #008080;">55</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">$tmpInfo</span>; <span style="color: #008000;">//</span><span style="color: #008000;"> 返回数据</span><span style="color: #008080;">56</span> <span style="color: #000000;"> }</span><span style="color: #008080;">57</span> <span style="color: #008080;">58</span> <span style="color: #008000;">/*</span><span style="color: #008000;">*</span><span style="color: #008080;">59</span> <span style="color: #008000;"> * 生成url</span><span style="color: #008080;">60</span> <span style="color: #008000;">*/</span><span style="color: #008080;">61</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> create_url(<span style="color: #800080;">$data</span><span style="color: #000000;">) {</span><span style="color: #008080;">62</span> <span style="color: #800080;">$temp</span> = '?'<span style="color: #000000;">;</span><span style="color: #008080;">63</span> <span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$data</span> <span style="color: #0000ff;">as</span> <span style="color: #800080;">$key</span> => <span style="color: #800080;">$item</span><span style="color: #000000;">) {</span><span style="color: #008080;">64</span> <span style="color: #800080;">$temp</span> = <span style="color: #800080;">$temp</span> . <span style="color: #800080;">$key</span> . '=' . <span style="color: #800080;">$item</span> . '&'<span style="color: #000000;">;</span><span style="color: #008080;">65</span> <span style="color: #000000;"> }</span><span style="color: #008080;">66</span> <span style="color: #0000ff;">return</span> <span style="color: #008080;">substr</span>(<span style="color: #800080;">$temp</span>, 0, -1<span style="color: #000000;">);</span><span style="color: #008080;">67</span> <span style="color: #000000;"> }</span><span style="color: #008080;">68</span> }
登入後複製1
<span style=
"font-family: 宋体; font-size: 16px;"
>关于curl_setopt(
$this
->ch, CURLOPT_SAFE_UPLOAD, false)会在微信图片资源上传博文中详细讲述它出现的心酸史,这里暂时用不到,不做解释</span>
登入後複製c. 授权基类
1
<span style=
"color: #008080;"
> 1</span> <span style=
"color: #000000;"
>php </span><span style=
"color: #008080;"
> 2</span> <span style=
"color: #000000;"
>
namespace
common\tools\wechat;</span><span style=
"color: #008080;"
> 3</span> <span style=
"color: #008080;"
> 4</span> <span style=
"color: #0000ff;"
>
use
</span><span style=
"color: #000000;"
> common\tools\wechat\ConfigTool;</span><span style=
"color: #008080;"
> 5</span> <span style=
"color: #0000ff;"
>
use
</span><span style=
"color: #000000;"
> common\tools\HttpsTool;</span><span style=
"color: #008080;"
> 6</span> <span style=
"color: #008000;"
>
/*</span><span style="color: #008000;">*</span><span style="color: #008080;"> 7</span> <span style="color: #008000;">* Weixin_oauth 类库</span><span style="color: #008080;"> 8</span> <span style="color: #008000;">*/
</span><span style=
"color: #008080;"
> 9</span> <span style=
"color: #0000ff;"
>
class
</span><span style=
"color: #000000;"
> OauthTool {</span><span style=
"color: #008080;"
>10</span> <span style=
"color: #008080;"
>11</span> <span style=
"color: #0000ff;"
>
public
</span> <span style=
"color: #800080;"
>
$conf
</span><span style=
"color: #000000;"
>;</span><span style=
"color: #008080;"
>12</span> <span style=
"color: #008080;"
>13</span> <span style=
"color: #0000ff;"
>
public
</span> <span style=
"color: #0000ff;"
>
function
</span><span style=
"color: #000000;"
> __construct(){</span><span style=
"color: #008080;"
>14</span> <span style=
"color: #800080;"
>
$re
</span> = <span style=
"color: #0000ff;"
>
new
</span><span style=
"color: #000000;"
> ConfigTool; </span><span style=
"color: #008080;"
>15</span> <span style=
"color: #800080;"
>
$this
</span>->conf = <span style=
"color: #800080;"
>
$re
</span>-><span style=
"color: #000000;"
>setConfig();</span><span style=
"color: #008080;"
>16</span> <span style=
"color: #000000;"
> } </span><span style=
"color: #008080;"
>17</span> <span style=
"color: #008080;"
>18</span> <span style=
"color: #008000;"
>
/*</span><span style="color: #008000;">*</span><span style="color: #008080;">19</span> <span style="color: #008000;"> * 生成用户授权的地址</span><span style="color: #008080;">20</span> <span style="color: #008000;"> * @param string 自定义需要保持的信息</span><span style="color: #008080;">21</span> <span style="color: #008000;"> * @param sting 请求的路由</span><span style="color: #008080;">22</span> <span style="color: #008000;"> * @param bool 是否是通过公众平台方式认真</span><span style="color: #008080;">23</span> <span style="color: #008000;">*/
</span><span style=
"color: #008080;"
>24</span> <span style=
"color: #0000ff;"
>
public
</span> <span style=
"color: #0000ff;"
>
function
</span> authorize_addr(<span style=
"color: #800080;"
>
$route
</span>, <span style=
"color: #800080;"
>
$state
</span>=
''
, <span style=
"color: #800080;"
>
$mp
</span>=<span style=
"color: #0000ff;"
>false</span><span style=
"color: #000000;"
>) {</span><span style=
"color: #008080;"
>25</span> <span style=
"color: #008080;"
>26</span> <span style=
"color: #0000ff;"
>
if
</span> (<span style=
"color: #800080;"
>
$mp
</span><span style=
"color: #000000;"
>) {</span><span style=
"color: #008080;"
>27</span> <span style=
"color: #800080;"
>
$data
</span> =<span style=
"color: #000000;"
> [</span><span style=
"color: #008080;"
>28</span>
'appid'
=> <span style=
"color: #800080;"
>
$this
</span>->conf[
'appid'
],<span style=
"color: #008080;"
>29</span>
'secret'
=> <span style=
"color: #800080;"
>
$this
</span>->conf[
'token'
],<span style=
"color: #008080;"
>30</span>
'grant_type'
=>
'client_credential'
<span style=
"color: #008080;"
>31</span> <span style=
"color: #000000;"
> ];</span><span style=
"color: #008080;"
>32</span> <span style=
"color: #800080;"
>
$url
</span> = <span style=
"color: #800080;"
>
$this
</span>->conf[
'mp_authorize_url'
<span style=
"color: #000000;"
>];</span><span style=
"color: #008080;"
>33</span> } <span style=
"color: #0000ff;"
>
else
</span><span style=
"color: #000000;"
> {</span><span style=
"color: #008080;"
>34</span> <span style=
"color: #800080;"
>
$data
</span> =<span style=
"color: #000000;"
> [</span><span style=
"color: #008080;"
>35</span>
'appid'
=> <span style=
"color: #800080;"
>
$this
</span>->conf[
'appid'
], <span style=
"color: #008000;"
>
//</span><span style="color: #008000;">公众号唯一标识</span><span style="color: #008080;">36</span> 'redirect_uri' => <span style="color: #008080;">urlencode</span>(<span style="color: #800080;">$this</span>->conf['redirect_uri'] . <span style="color: #800080;">$route</span>), <span style="color: #008000;">//</span><span style="color: #008000;">授权后重定向的回调链接地址</span><span style="color: #008080;">37</span> 'response_type' => 'code', <span style="color: #008000;">//</span><span style="color: #008000;">返回类型,此处填写code</span><span style="color: #008080;">38</span> 'scope'=><span style="color: #800080;">$this</span>->conf['scope'], <span style="color: #008000;">//</span><span style="color: #008000;">应用授权作用域</span><span style="color: #008080;">39</span> 'state'=><span style="color: #800080;">$state</span>, <span style="color: #008000;">//</span><span style="color: #008000;">重定向后带上state参数,开发者可以填写任意参数</span><span style="color: #008080;">40</span> '#wechat_redirect'=>'' <span style="color: #008000;">//</span><span style="color: #008000;">直接在微信打开链接,可不填,做页面302重定向时必须带此参数</span><span style="color: #008080;">41</span> <span style="color: #000000;"> ];</span><span style="color: #008080;">42</span> <span style="color: #800080;">$url</span> = <span style="color: #800080;">$this</span>->conf['authorize_url'<span style="color: #000000;">];</span><span style="color: #008080;">43</span> <span style="color: #000000;"> }</span><span style="color: #008080;">44</span> <span style="color: #008080;">45</span> <span style="color: #800080;">$send</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> HttpsTool;</span><span style="color: #008080;">46</span> <span style="color: #008000;">//</span><span style="color: #008000;">var_dump($url . $send->create_url($data));exit;</span><span style="color: #008080;">47</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">$url</span> . <span style="color: #800080;">$send</span>->create_url(<span style="color: #800080;">$data</span><span style="color: #000000;">);</span><span style="color: #008080;">48</span> <span style="color: #000000;"> }</span><span style="color: #008080;">49</span> <span style="color: #008080;">50</span> <span style="color: #008000;">/*</span><span style="color: #008000;">*</span><span style="color: #008080;">51</span> <span style="color: #008000;"> * 获取 access token</span><span style="color: #008080;">52</span> <span style="color: #008000;"> * @param string 用于换取access token的code,微信提供</span><span style="color: #008080;">53</span> <span style="color: #008000;">*/</span><span style="color: #008080;">54</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> access_token(<span style="color: #800080;">$code</span><span style="color: #000000;">) {</span><span style="color: #008080;">55</span> <span style="color: #008080;">56</span> <span style="color: #800080;">$data</span> =<span style="color: #000000;"> [</span><span style="color: #008080;">57</span> 'appid' => <span style="color: #800080;">$this</span>->conf['appid'],<span style="color: #008080;">58</span> 'secret' => <span style="color: #800080;">$this</span>->conf['secret'],<span style="color: #008080;">59</span> 'code' => <span style="color: #800080;">$code</span>,<span style="color: #008080;">60</span> 'grant_type' => 'authorization_code'<span style="color: #008080;">61</span> <span style="color: #000000;"> ];</span><span style="color: #008080;">62</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 生成授权url</span><span style="color: #008080;">63</span> <span style="color: #800080;">$url</span> = <span style="color: #800080;">$this</span>->conf['access_token_url'<span style="color: #000000;">];</span><span style="color: #008080;">64</span> <span style="color: #008080;">65</span> <span style="color: #800080;">$send</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> HttpsTool;</span><span style="color: #008080;">66</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">$send</span>->send_request(<span style="color: #800080;">$url</span>, <span style="color: #800080;">$data</span><span style="color: #000000;">);</span><span style="color: #008080;">67</span> <span style="color: #000000;"> }</span><span style="color: #008080;">68</span> <span style="color: #008080;">69</span> <span style="color: #008000;">/*</span><span style="color: #008000;">*</span><span style="color: #008080;">70</span> <span style="color: #008000;"> * 获取用户信息</span><span style="color: #008080;">71</span> <span style="color: #008000;"> * @param string access token</span><span style="color: #008080;">72</span> <span style="color: #008000;"> * @param string 用户的open id</span><span style="color: #008080;">73</span> <span style="color: #008000;">*/</span><span style="color: #008080;">74</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> userinfo(<span style="color: #800080;">$token</span>, <span style="color: #800080;">$openid</span><span style="color: #000000;">) {</span><span style="color: #008080;">75</span> <span style="color: #008080;">76</span> <span style="color: #800080;">$data</span> =<span style="color: #000000;"> [</span><span style="color: #008080;">77</span> 'access_token' => <span style="color: #800080;">$token</span>,<span style="color: #008080;">78</span> 'openid' => <span style="color: #800080;">$openid</span>,<span style="color: #008080;">79</span> 'lang' => <span style="color: #800080;">$this</span>->conf['lang'<span style="color: #000000;">]</span><span style="color: #008080;">80</span> <span style="color: #000000;"> ];</span><span style="color: #008080;">81</span> <span style="color: #008000;">//</span><span style="color: #008000;"> 生成授权url</span><span style="color: #008080;">82</span> <span style="color: #800080;">$url</span> = <span style="color: #800080;">$this</span>->conf['userinfo_url'<span style="color: #000000;">];</span><span style="color: #008080;">83</span> <span style="color: #008080;">84</span> <span style="color: #800080;">$send</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> HttpsTool;</span><span style="color: #008080;">85</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">$send</span>->send_request(<span style="color: #800080;">$url</span>, <span style="color: #800080;">$data</span><span style="color: #000000;">);</span><span style="color: #008080;">86</span> <span style="color: #000000;"> }</span><span style="color: #008080;">87</span> <span style="color: #008080;">88</span> }
登入後複製d. 授权基类调用及用户数据处理(在控制器调用前,先对用户数据存入或更新)
1
<span style=
"color: #008080;"
> 1</span> <span style=
"color: #000000;"
>php</span><span style=
"color: #008080;"
> 2</span> <span style=
"color: #000000;"
>
namespace
wechat\controllers\classes;</span><span style=
"color: #008080;"
> 3</span> <span style=
"color: #008080;"
> 4</span> <span style=
"color: #0000ff;"
>
use
</span><span style=
"color: #000000;"
> common\tools\wechat\OauthTool;</span><span style=
"color: #008080;"
> 5</span> <span style=
"color: #0000ff;"
>
use
</span><span style=
"color: #000000;"
> common\models\User;</span><span style=
"color: #008080;"
> 6</span> <span style=
"color: #0000ff;"
>
use
</span><span style=
"color: #000000;"
> common\tools\EmojiTool;</span><span style=
"color: #008080;"
> 7</span> <span style=
"color: #008080;"
> 8</span> <span style=
"color: #008000;"
>
/*</span><span style="color: #008000;">*</span><span style="color: #008080;"> 9</span> <span style="color: #008000;"> * 微信用户基本信息获取</span><span style="color: #008080;">10</span> <span style="color: #008000;">*/
</span><span style=
"color: #008080;"
>11</span> <span style=
"color: #0000ff;"
>
class
</span><span style=
"color: #000000;"
> UserinfoClass {</span><span style=
"color: #008080;"
>12</span> <span style=
"color: #008080;"
>13</span> <span style=
"color: #008000;"
>
/*</span><span style="color: #008000;">*</span><span style="color: #008080;">14</span> <span style="color: #008000;"> * 用户授权并获取code </span><span style="color: #008080;">15</span> <span style="color: #008000;"> * @return string 用户code</span><span style="color: #008080;">16</span> <span style="color: #008000;">*/
</span><span style=
"color: #008080;"
>17</span> <span style=
"color: #0000ff;"
>
public
</span> <span style=
"color: #0000ff;"
>
function
</span> getCode(<span style=
"color: #800080;"
>
$route
</span>, <span style=
"color: #800080;"
>
$state
</span><span style=
"color: #000000;"
>){</span><span style=
"color: #008080;"
>18</span> <span style=
"color: #008080;"
>19</span> <span style=
"color: #800080;"
>
$re
</span> = <span style=
"color: #0000ff;"
>
new
</span><span style=
"color: #000000;"
> OauthTool;</span><span style=
"color: #008080;"
>20</span> <span style=
"color: #800080;"
>
$request
</span> = <span style=
"color: #800080;"
>
$re
</span>->authorize_addr(<span style=
"color: #800080;"
>
$route
</span>, <span style=
"color: #800080;"
>
$state
</span><span style=
"color: #000000;"
>);</span><span style=
"color: #008080;"
>21</span> <span style=
"color: #800080;"
>
$code
</span> = <span style=
"color: #0000ff;"
>isset</span>(<span style=
"color: #800080;"
>
$_GET
</span>[
'code'
]) ? <span style=
"color: #800080;"
>
$_GET
</span>[
'code'
] :
''
<span style=
"color: #000000;"
>;</span><span style=
"color: #008080;"
>22</span> <span style=
"color: #008080;"
>23</span> <span style=
"color: #0000ff;"
>
return
</span> [<span style=
"color: #800080;"
>
$request
</span>,<span style=
"color: #800080;"
>
$code
</span><span style=
"color: #000000;"
>];</span><span style=
"color: #008080;"
>24</span> <span style=
"color: #000000;"
> }</span><span style=
"color: #008080;"
>25</span> <span style=
"color: #008080;"
>26</span> <span style=
"color: #008000;"
>
/*</span><span style="color: #008000;">*</span><span style="color: #008080;">27</span> <span style="color: #008000;"> * 获取用户信息并写入数据库(之后加参数传给code)</span><span style="color: #008080;">28</span> <span style="color: #008000;">*/
</span><span style=
"color: #008080;"
>29</span> <span style=
"color: #0000ff;"
>
public
</span> <span style=
"color: #0000ff;"
>
function
</span> info(<span style=
"color: #800080;"
>
$code
</span><span style=
"color: #000000;"
>) {</span><span style=
"color: #008080;"
>30</span> <span style=
"color: #800080;"
>
$re
</span> = <span style=
"color: #0000ff;"
>
new
</span><span style=
"color: #000000;"
> OauthTool;</span><span style=
"color: #008080;"
>31</span> <span style=
"color: #008000;"
>
//</span><span style="color: #008000;">获取access token</span><span style="color: #008080;">32</span> <span style="color: #800080;">$access</span> = <span style="color: #800080;">$re</span>->access_token(<span style="color: #800080;">$code</span><span style="color: #000000;">);</span><span style="color: #008080;">33</span> <span style="color: #800080;">$token</span> = json_decode(<span style="color: #800080;">$access</span>,<span style="color: #0000ff;">true</span><span style="color: #000000;">);</span><span style="color: #008080;">34</span> <span style="color: #008000;">//</span><span style="color: #008000;">header("Content-type: text/html; charset=gbk"); </span><span style="color: #008080;">35</span> <span style="color: #008000;"> //获取用户信息</span><span style="color: #008080;">36</span> <span style="color: #0000ff;">if</span>(<span style="color: #008080;">count</span>(<span style="color: #800080;">$token</span>) != 2<span style="color: #000000;">) {</span><span style="color: #008080;">37</span> <span style="color: #800080;">$response</span> = <span style="color: #800080;">$re</span>->userinfo(<span style="color: #800080;">$token</span>['access_token'], <span style="color: #800080;">$token</span>['openid'<span style="color: #000000;">]);</span><span style="color: #008080;">38</span> <span style="color: #800080;">$user</span> = json_decode(<span style="color: #800080;">$response</span>,<span style="color: #0000ff;">true</span><span style="color: #000000;">);</span><span style="color: #008080;">39</span> <span style="color: #008000;">//</span><span style="color: #008000;">用户昵称转换</span><span style="color: #008080;">40</span> <span style="color: #008000;"> //$user['nickname'] = EmojiTool::emoji_trans($user['nickname']);</span><span style="color: #008080;">41</span> <span style="color: #008080;">42</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$model</span> = User::findOne(['openid' => <span style="color: #800080;">$user</span>['openid'] ])) { <span style="color: #008000;">//</span><span style="color: #008000;">用户已存在更新数据</span><span style="color: #008080;">43</span> <span style="color: #800080;">$model</span>->attributes = <span style="color: #800080;">$user</span><span style="color: #000000;">;</span><span style="color: #008080;">44</span> <span style="color: #800080;">$model</span>->modify_time = <span style="color: #008080;">time</span><span style="color: #000000;">();</span><span style="color: #008080;">45</span> <span style="color: #800080;">$model</span>->save(<span style="color: #0000ff;">false</span><span style="color: #000000;">);</span><span style="color: #008080;">46</span> }<span style="color: #0000ff;">else</span>{ <span style="color: #008000;">//</span><span style="color: #008000;">用户不存在写入</span><span style="color: #008080;">47</span> <span style="color: #800080;">$model</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> User;</span><span style="color: #008080;">48</span> <span style="color: #800080;">$model</span>->attributes = <span style="color: #800080;">$user</span><span style="color: #000000;">;</span><span style="color: #008080;">49</span> <span style="color: #800080;">$model</span>->create_time = <span style="color: #008080;">time</span><span style="color: #000000;">();</span><span style="color: #008080;">50</span> <span style="color: #800080;">$model</span>->save(<span style="color: #0000ff;">false</span><span style="color: #000000;">);</span><span style="color: #008080;">51</span> <span style="color: #000000;"> }</span><span style="color: #008080;">52</span> <span style="color: #000000;"> }</span><span style="color: #008080;">53</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$model</span>->id) ? <span style="color: #800080;">$model</span>->id : ''<span style="color: #000000;">;</span><span style="color: #008080;">54</span> <span style="color: #000000;"> }</span><span style="color: #008080;">55</span> <span style="color: #008080;">56</span> }
登入後複製e. 控制器调用(这里只贴其中一个方法)
1
<span style=
"color: #008080;"
> 1</span> <span style=
"color: #008000;"
>
/*</span><span style="color: #008000;">*</span><span style="color: #008080;"> 2</span> <span style="color: #008000;"> * 产品列表</span><span style="color: #008080;"> 3</span> <span style="color: #008000;"> * @return object 所有可用产品信息</span><span style="color: #008080;"> 4</span> <span style="color: #008000;">*/
</span><span style=
"color: #008080;"
> 5</span> <span style=
"color: #0000ff;"
>
public
</span> <span style=
"color: #0000ff;"
>
function
</span><span style=
"color: #000000;"
> actionIndex(){</span><span style=
"color: #008080;"
> 6</span> <span style=
"color: #008000;"
>
//</span><span style="color: #008000;">判断页面是否自动刷新</span><span style="color: #008080;"> 7</span> <span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$_GET</span>['state'<span style="color: #000000;">])) {</span><span style="color: #008080;"> 8</span> <span style="color: #800080;">$refresh</span> = 0<span style="color: #000000;">;</span><span style="color: #008080;"> 9</span> }<span style="color: #0000ff;">else</span><span style="color: #000000;">{</span><span style="color: #008080;">10</span> <span style="color: #800080;">$refresh</span> = 1<span style="color: #000000;">;</span><span style="color: #008080;">11</span> <span style="color: #000000;"> }</span><span style="color: #008080;">12</span> <span style="color: #008080;">13</span> <span style="color: #008000;">//</span><span style="color: #008000;">获取用户code</span><span style="color: #008080;">14</span> <span style="color: #800080;">$user</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> UserinfoClass;</span><span style="color: #008080;">15</span> <span style="color: #800080;">$request</span> = <span style="color: #800080;">$user</span>->getCode('r=store/index', 1<span style="color: #000000;">);</span><span style="color: #008080;">16</span> <span style="color: #008080;">17</span> <span style="color: #008000;">//</span><span style="color: #008000;">该用户userid</span><span style="color: #008080;">18</span> <span style="color: #800080;">$userid</span> = <span style="color: #800080;">$user</span>->info(<span style="color: #800080;">$request</span>[1<span style="color: #000000;">]);</span><span style="color: #008080;">19</span> <span style="color: #008080;">20</span> <span style="color: #800080;">$model</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> Product;</span><span style="color: #008080;">21</span> <span style="color: #800080;">$list</span> = <span style="color: #800080;">$model</span>->find()->where(['status' => 1])-><span style="color: #000000;">all();</span><span style="color: #008080;">22</span> <span style="color: #008080;">23</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->render('index',['list' => <span style="color: #800080;">$list</span>, 'refresh' => <span style="color: #800080;">$refresh</span>, 'userid' => <span style="color: #800080;">$userid</span>, 'request' => <span style="color: #800080;">$request</span><span style="color: #000000;">]);</span><span style="color: #008080;">24</span> }
登入後複製程序要求用户打开产品列表即获取用户信息并存入数据库,其中设计了几个变量作用如下:
$refresh:判断页面是否刷新,由于首次打开页面未进行oauth验证时才自动请求验证,避免反复刷新,这里用回调的state参数作为判断依据且设state=1(若有特定参数需要可将state赋值为所需值);
$request:即为验证请求地址
f. 视图自动刷新
只需要在视图中添加以下js代码即可
1
<span style=
"color: #008080;"
> 1</span> <script type=
"text/javascript"
><span style=
"color: #008080;"
> 2 <span style=
"color: #008080;"
> 3 <span style=
"color: #008000;"
>
//<span style="color: #008000;">自动请求获取code<span style="color: #008080;"> 4 $(<span style="color: #0000ff;">function<span style="color: #000000;">(){<span style="color: #008080;"> 5 <span style="color: #0000ff;">var refresh = <?= <span style="color: #800080;">$refresh; ?><span style="color: #000000;">;<span style="color: #008080;"> 6 <span style="color: #0000ff;">var request = '<?= $request[0]; ?>'<span style="color: #000000;">;<span style="color: #008080;"> 7 <span style="color: #0000ff;">if(refresh == 1<span style="color: #000000;">){<span style="color: #008080;"> 8 console.<span style="color: #008080;">log(1<span style="color: #000000;">);<span style="color: #008080;"> 9 location =<span style="color: #000000;"> request;<span style="color: #008080;">10 <span style="color: #000000;"> }<span style="color: #008080;">11 <span style="color: #000000;"> });<span style="color: #008080;">12 </script>
登入後複製特此声明:相关文章均为查阅资料、阅读大神博文后结合实际开发情况遇到的问题整理而成,能找到原博的必会署名,找不到原博而引用的内容还望原博主海涵

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

「你的組織要求你更改PIN訊息」將顯示在登入畫面上。當在使用基於組織的帳戶設定的電腦上達到PIN過期限制時,就會發生這種情況,在該電腦上,他們可以控制個人設備。但是,如果您使用個人帳戶設定了Windows,則理想情況下不應顯示錯誤訊息。雖然情況並非總是如此。大多數遇到錯誤的使用者使用個人帳戶報告。為什麼我的組織要求我在Windows11上更改我的PIN?可能是您的帳戶與組織相關聯,您的主要方法應該是驗證這一點。聯絡網域管理員會有所幫助!此外,配置錯誤的本機原則設定或不正確的登錄項目也可能導致錯誤。即

Windows11將清新優雅的設計帶到了最前沿;現代介面可讓您個性化和更改最精細的細節,例如視窗邊框。在本指南中,我們將討論逐步說明,以協助您在Windows作業系統中建立反映您的風格的環境。如何更改視窗邊框設定?按+開啟“設定”應用程式。 WindowsI前往個人化,然後按一下顏色設定。顏色變更視窗邊框設定視窗11「寬度=」643「高度=」500「>找到在標題列和視窗邊框上顯示強調色選項,然後切換它旁邊的開關。若要在「開始」功能表和工作列上顯示主題色,請開啟「在開始」功能表和工作列上顯示主題

預設情況下,Windows11上的標題列顏色取決於您選擇的深色/淺色主題。但是,您可以將其變更為所需的任何顏色。在本指南中,我們將討論三種方法的逐步說明,以更改它並個性化您的桌面體驗,使其具有視覺吸引力。是否可以更改活動和非活動視窗的標題列顏色?是的,您可以使用「設定」套用變更活動視窗的標題列顏色,也可以使用登錄編輯程式變更非活動視窗的標題列顏色。若要了解這些步驟,請前往下一部分。如何在Windows11中變更標題列的顏色? 1.使用「設定」應用程式按+開啟設定視窗。 WindowsI前往“個人化”,然

工作列縮圖可能很有趣,但它們也可能分散注意力或煩人。考慮到您將滑鼠懸停在該區域的頻率,您可能無意中關閉了重要視窗幾次。另一個缺點是它使用更多的系統資源,因此,如果您一直在尋找一種提高資源效率的方法,我們將向您展示如何停用它。不過,如果您的硬體規格可以處理它並且您喜歡預覽版,則可以啟用它。如何在Windows11中啟用工作列縮圖預覽? 1.使用「設定」應用程式點擊鍵並點選設定。 Windows按一下系統,然後選擇關於。點選高級系統設定。導航至“進階”選項卡,然後選擇“效能”下的“設定”。在「視覺效果」選

您是否在Windows安裝程式頁面上看到「出現問題」以及「OOBELANGUAGE」語句? Windows的安裝有時會因此類錯誤而停止。 OOBE表示開箱即用的體驗。正如錯誤提示所表示的那樣,這是與OOBE語言選擇相關的問題。沒有什麼好擔心的,你可以透過OOBE螢幕本身的漂亮註冊表編輯來解決這個問題。快速修復–1.點選OOBE應用底部的「重試」按鈕。這將繼續進行該過程,而不會再打嗝。 2.使用電源按鈕強制關閉系統。系統重新啟動後,OOBE應繼續。 3.斷開系統與網際網路的連接。在脫機模式下完成OOBE的所

在Windows11上的顯示縮放方面,我們都有不同的偏好。有些人喜歡大圖標,有些人喜歡小圖標。但是,我們都同意擁有正確的縮放比例很重要。字體縮放不良或圖像過度縮放可能是工作時真正的生產力殺手,因此您需要知道如何自訂以充分利用系統功能。自訂縮放的優點:對於難以閱讀螢幕上的文字的人來說,這是一個有用的功能。它可以幫助您一次在螢幕上查看更多內容。您可以建立僅適用於某些監視器和應用程式的自訂擴充功能設定檔。可以幫助提高低階硬體的效能。它使您可以更好地控制螢幕上的內容。如何在Windows11

螢幕亮度是使用現代計算設備不可或缺的一部分,尤其是當您長時間注視螢幕時。它可以幫助您減輕眼睛疲勞,提高易讀性,並輕鬆有效地查看內容。但是,根據您的設置,有時很難管理亮度,尤其是在具有新UI更改的Windows11上。如果您在調整亮度時遇到問題,以下是在Windows11上管理亮度的所有方法。如何在Windows11上變更亮度[10種方式解釋]單一顯示器使用者可以使用下列方法在Windows11上調整亮度。這包括使用單一顯示器的桌上型電腦系統以及筆記型電腦。讓我們開始吧。方法1:使用操作中心操作中心是訪問

許多用戶在選擇智慧型手錶的時候都會選擇的華為的品牌,其中華為GT3pro和GT4都是非常熱門的選擇,不少用戶都很好奇華為GT3pro和GT4有什麼區別,下面就給大家介紹一下二者。華為GT3pro和GT4有什麼差別一、外觀GT4:46mm和41mm,材質是玻璃鏡板+不鏽鋼機身+高分纖維後殼。 GT3pro:46.6mm和42.9mm,材質是藍寶石玻璃鏡+鈦金屬機身/陶瓷機身+陶瓷後殼二、健康GT4:採用最新的華為Truseen5.5+演算法,結果會更加的精準。 GT3pro:多了ECG心電圖和血管及安
