{"id":68164,"date":"2018-07-12T14:39:05","date_gmt":"2018-07-12T06:39:05","guid":{"rendered":"http:\/\/www.xiaoyebailong.com\/?p=68164"},"modified":"2018-07-24T04:39:15","modified_gmt":"2018-07-23T20:39:15","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e8%8e%b7%e5%8f%96%e5%be%ae%e4%bf%a1%e7%bb%91%e5%ae%9a%e6%8e%88%e6%9d%83%e6%89%8b%e6%9c%ba%e5%8f%b7getphonenumber-%e5%85%a8%e6%b5%81%e7%a8%8b%e5%8f%8a","status":"publish","type":"post","link":"http:\/\/www.xiaoyebailong.com\/index.php\/2018\/07\/12\/68164.htm","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u83b7\u53d6\u5fae\u4fe1\u7ed1\u5b9a\u6388\u6743\u624b\u673a\u53f7getPhoneNumber \u5168\u6d41\u7a0b\u53ca\u51fa\u73b0\u624b\u673a\u53f7\u5e26*\u53f7\u95ee\u9898\u8be6\u89e3"},"content":{"rendered":"<p>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u6587\u6863\u4e2d\u7ed9\u51fa\u5982\u4e0b\u793a\u4f8b<\/p>\n<p>\u83b7\u53d6\u5fae\u4fe1\u7528\u6237\u7ed1\u5b9a\u7684\u624b\u673a\u53f7\uff0c\u9700\u5148\u8c03\u7528<a rel=\"nofollow\" href=\"https:\/\/mp.weixin.qq.com\/debug\/wxadoc\/dev\/api\/api-login.html?t=201839#wxloginobject\" target=\"_blank\" rel=\"nofollow noopener\">login<\/a>\u63a5\u53e3\u3002<\/p>\n<p>\u56e0\u4e3a\u9700\u8981\u7528\u6237\u4e3b\u52a8\u89e6\u53d1\u624d\u80fd\u53d1\u8d77\u83b7\u53d6\u624b\u673a\u53f7\u63a5\u53e3\uff0c\u6240\u4ee5\u8be5\u529f\u80fd\u4e0d\u7531 API \u6765\u8c03\u7528\uff0c\u9700\u7528\u00a0<code>&lt;button&gt;<\/code>\u00a0\u7ec4\u4ef6\u7684\u70b9\u51fb\u6765\u89e6\u53d1\u3002<\/p>\n<p>\u6ce8\u610f\uff1a\u76ee\u524d\u8be5\u63a5\u53e3\u9488\u5bf9\u975e\u4e2a\u4eba\u5f00\u53d1\u8005\uff0c\u4e14\u5b8c\u6210\u4e86\u8ba4\u8bc1\u7684\u5c0f\u7a0b\u5e8f\u5f00\u653e\u3002\u9700\u8c28\u614e\u4f7f\u7528\uff0c\u82e5\u7528\u6237\u4e3e\u62a5\u8f83\u591a\u6216\u88ab\u53d1\u73b0\u5728\u4e0d\u5fc5\u8981\u573a\u666f\u4e0b\u4f7f\u7528\uff0c\u5fae\u4fe1\u6709\u6743\u6c38\u4e45\u56de\u6536\u8be5\u5c0f\u7a0b\u5e8f\u7684\u8be5\u63a5\u53e3\u6743\u9650\u3002<\/p>\n<h2><a name=\"t0\"><\/a>\u4f7f\u7528\u65b9\u6cd5<\/h2>\n<p>\u9700\u8981\u5c06\u00a0<code>&lt;button&gt;<\/code>\u00a0\u7ec4\u4ef6\u00a0<code>open-type<\/code>\u00a0\u7684\u503c\u8bbe\u7f6e\u4e3a\u00a0<code>getPhoneNumber<\/code>\uff0c\u5f53\u7528\u6237\u70b9\u51fb\u5e76\u540c\u610f\u4e4b\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u00a0<code>bindgetphonenumber<\/code>\u00a0\u4e8b\u4ef6\u56de\u8c03\u83b7\u53d6\u5230\u5fae\u4fe1\u670d\u52a1\u5668\u8fd4\u56de\u7684\u52a0\u5bc6\u6570\u636e\uff0c \u7136\u540e\u5728\u7b2c\u4e09\u65b9\u670d\u52a1\u7aef\u7ed3\u5408\u00a0<code>session_key<\/code>\u00a0\u4ee5\u53ca\u00a0<code>app_id<\/code>\u00a0\u8fdb\u884c\u89e3\u5bc6\u83b7\u53d6\u624b\u673a\u53f7\u3002<\/p>\n<h2><a name=\"t1\"><\/a>\u6ce8\u610f<\/h2>\n<p>\u5728\u56de\u8c03\u4e2d\u8c03\u7528\u00a0<code>wx.login<\/code>\u00a0\u767b\u5f55\uff0c\u53ef\u80fd\u4f1a\u5237\u65b0\u767b\u5f55\u6001\u3002\u6b64\u65f6\u670d\u52a1\u5668\u4f7f\u7528 code \u6362\u53d6\u7684 sessionKey \u4e0d\u662f\u52a0\u5bc6\u65f6\u4f7f\u7528\u7684 sessionKey\uff0c\u5bfc\u81f4\u89e3\u5bc6\u5931\u8d25\u3002\u5efa\u8bae\u5f00\u53d1\u8005\u63d0\u524d\u8fdb\u884c\u00a0<code>login<\/code>\uff1b\u6216\u8005\u5728\u56de\u8c03\u4e2d\u5148\u4f7f\u7528\u00a0<code>checkSession<\/code>\u00a0\u8fdb\u884c\u767b\u5f55\u6001\u68c0\u67e5\uff0c\u907f\u514d\u00a0<code>login<\/code>\u00a0\u5237\u65b0\u767b\u5f55\u6001\u3002<\/p>\n<h2><a name=\"t2\"><\/a>\u4f8b\u5b50<\/h2>\n<p>&lt;button open-type=&#8221;getPhoneNumber&#8221; bindgetphonenumber=&#8221;getPhoneNumber&#8221;&gt; &lt;\/button&gt;<\/p>\n<p>Page({<br \/>\ngetPhoneNumber: function(e) {<br \/>\nconsole.log(e.detail.errMsg)<br \/>\nconsole.log(e.detail.iv)<br \/>\nconsole.log(e.detail.encryptedData)<br \/>\n}<br \/>\n})<\/p>\n<p>&nbsp;<\/p>\n<h2>\u8fd4\u56de\u53c2\u6570\u8bf4\u660e<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u53c2\u6570<\/th>\n<th>\u7c7b\u578b<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>encryptedData<\/td>\n<td>String<\/td>\n<td>\u5305\u62ec\u654f\u611f\u6570\u636e\u5728\u5185\u7684\u5b8c\u6574\u7528\u6237\u4fe1\u606f\u7684\u52a0\u5bc6\u6570\u636e\uff0c\u8be6\u7ec6\u89c1<a rel=\"nofollow\" href=\"https:\/\/mp.weixin.qq.com\/debug\/wxadoc\/dev\/api\/signature.html?t=201839#%E5%8A%A0%E5%AF%86%E6%95%B0%E6%8D%AE%E8%A7%A3%E5%AF%86%E7%AE%97%E6%B3%95\" target=\"_blank\" rel=\"nofollow noopener\">\u52a0\u5bc6\u6570\u636e\u89e3\u5bc6\u7b97\u6cd5<\/a><\/td>\n<\/tr>\n<tr>\n<td>iv<\/td>\n<td>String<\/td>\n<td>\u52a0\u5bc6\u7b97\u6cd5\u7684\u521d\u59cb\u5411\u91cf\uff0c\u8be6\u7ec6\u89c1<a rel=\"nofollow\" href=\"https:\/\/mp.weixin.qq.com\/debug\/wxadoc\/dev\/api\/signature.html?t=201839#%E5%8A%A0%E5%AF%86%E6%95%B0%E6%8D%AE%E8%A7%A3%E5%AF%86%E7%AE%97%E6%B3%95\" target=\"_blank\" rel=\"nofollow noopener\">\u52a0\u5bc6\u6570\u636e\u89e3\u5bc6\u7b97\u6cd5<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>encryptedData \u89e3\u5bc6\u540e\u4e3a\u4ee5\u4e0b json \u7ed3\u6784\uff0c\u8be6\u89c1<a rel=\"nofollow\" href=\"https:\/\/mp.weixin.qq.com\/debug\/wxadoc\/dev\/api\/signature.html?t=201839#%E5%8A%A0%E5%AF%86%E6%95%B0%E6%8D%AE%E8%A7%A3%E5%AF%86%E7%AE%97%E6%B3%95\" target=\"_blank\" rel=\"nofollow noopener\">\u52a0\u5bc6\u6570\u636e\u89e3\u5bc6\u7b97\u6cd5<\/a><\/p>\n<pre><code class=\"lang-json\">{\r\n    <span class=\"hljs-string\">\"phoneNumber\"<\/span>: <span class=\"hljs-string\">\"13580006666\"<\/span>,  \r\n    <span class=\"hljs-string\">\"purePhoneNumber\"<\/span>: <span class=\"hljs-string\">\"13580006666\"<\/span>, \r\n    <span class=\"hljs-string\">\"countryCode\"<\/span>: <span class=\"hljs-string\">\"86\"<\/span>,\r\n    <span class=\"hljs-string\">\"watermark\"<\/span>:\r\n    {\r\n        <span class=\"hljs-string\">\"appid\"<\/span>:<span class=\"hljs-string\">\"APPID\"<\/span>,\r\n        <span class=\"hljs-string\">\"timestamp\"<\/span>:TIMESTAMP\r\n    }\r\n}<\/code><\/pre>\n<p>\u4f46\u662f\u5230\u8fd9\u91cc\u4f60\u4f1a\u53d1\u73b0\u5176\u5b9e\u6839\u672c\u4e0d\u8be6\u5c3d\u5c24\u5176\u662f\u89e3\u5bc6\u548c\u9519\u8bef\u4ee3\u7801\u65b9\u9762<\/p>\n<p><strong>\u9996\u5148\u5982\u624b\u518c\u6240\u8ff0\uff0c\u89e3\u6790\u52a0\u5bc6\u6570\u636e\u5305\u4e0d\u592a\u660e\u767d\u6211\u7ed9\u5927\u5bb6\u8d34\u4e2a\u793a\u4f8b<\/strong><\/p>\n<div>\n<div>getPhoneNumber:\u00a0function\u00a0(e) {<\/div>\n<div>console.log(e.detail.iv);<\/div>\n<div>console.log(e.detail.encryptedData);<\/div>\n<div>wx.login({<\/div>\n<div>success: res =&gt; {<\/div>\n<div>console.log(res.code);<\/div>\n<div>wx.request({<\/div>\n<div>url:\u00a0&#8216;https:\/\/\u4f60\u7684\u89e3\u5bc6\u5730\u5740&#8217;,<\/div>\n<div>data: {<\/div>\n<div>&#8216;encryptedData&#8217;: encodeURIComponent(e.detail.encryptedData),<\/div>\n<div>&#8216;iv&#8217;: e.detail.iv,<\/div>\n<div>&#8216;code&#8217;: res.code<\/div>\n<div>},<\/div>\n<div>method:\u00a0&#8216;GET&#8217;,\u00a0\/\/ OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT<\/div>\n<div>header: {<\/div>\n<div>&#8216;content-type&#8217;:&#8217;application\/json&#8217;<\/div>\n<div>},\u00a0\/\/ \u8bbe\u7f6e\u8bf7\u6c42\u7684 header<\/div>\n<div>success:\u00a0function\u00a0(res) {<\/div>\n<div>if\u00a0(res.status ==1) {\/\/\u6211\u540e\u53f0\u8bbe\u7f6e\u7684\u8fd4\u56de\u503c\u4e3a1\u662f\u6b63\u786e<\/div>\n<div>\/\/\u5b58\u5165\u7f13\u5b58\u5373\u53ef<\/div>\n<div>wx.setStorageSync(&#8216;phone&#8217;, res.phone);<\/div>\n<div>}<\/div>\n<div>},<\/div>\n<div>fail:\u00a0function\u00a0(err) {<\/div>\n<div>console.log(err);<\/div>\n<div>}<\/div>\n<div>})<\/div>\n<div>}<\/div>\n<div>})<\/div>\n<div>}<\/div>\n<div><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u6587\u6863\u4e2d\u7ed9\u51fa\u5982\u4e0b\u793a\u4f8b \u83b7\u53d6\u5fae\u4fe1\u7528\u6237\u7ed1\u5b9a\u7684\u624b\u673a\u53f7\uff0c\u9700\u5148\u8c03\u7528login\u63a5\u53e3\u3002 \u56e0\u4e3a\u9700\u8981\u7528\u6237\u4e3b\u52a8\u89e6\u53d1\u624d\u80fd\u53d1\u8d77\u83b7\u53d6\u624b\u673a\u53f7\u63a5\u53e3\uff0c\u6240\u4ee5\u8be5\u529f\u80fd\u4e0d\u7531 API \u6765\u8c03\u7528\uff0c\u9700\u7528\u00a0&lt;button&gt;\u00a0\u7ec4\u4ef6\u7684\u70b9\u51fb\u6765\u89e6\u53d1\u3002 \u6ce8\u610f\uff1a\u76ee\u524d\u8be5\u63a5\u53e3\u9488\u5bf9\u975e\u4e2a\u4eba&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[414,413],"topic":[],"class_list":["post-68164","post","type-post","status-publish","format-standard","hentry","category-wx","tag-getphonenumber","tag-413"],"_links":{"self":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/68164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/comments?post=68164"}],"version-history":[{"count":1,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/68164\/revisions"}],"predecessor-version":[{"id":68165,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/68164\/revisions\/68165"}],"wp:attachment":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/media?parent=68164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/categories?post=68164"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/tags?post=68164"},{"taxonomy":"topic","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/topic?post=68164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}