{"id":401,"date":"2019-03-25T02:38:50","date_gmt":"2019-03-24T10:38:50","guid":{"rendered":"https:\/\/chenbing.name\/?p=401"},"modified":"2020-05-22T14:58:10","modified_gmt":"2020-05-22T06:58:10","slug":"%e6%9c%80%e6%96%b0%e5%b0%8f%e7%a8%8b%e5%ba%8f%e6%8e%88%e6%9d%83%e7%9a%84%e8%af%a6%e7%bb%86%e5%a4%84%e7%90%86%e6%80%9d%e8%b7%af%ef%bc%88%e4%b8%80%ef%bc%89","status":"publish","type":"post","link":"https:\/\/chenbing.name\/blog\/401\/","title":{"rendered":"\u6700\u65b0\u5c0f\u7a0b\u5e8f\u6388\u6743\u7684\u8be6\u7ec6\u5904\u7406\u601d\u8def\uff08\u4e00\uff09"},"content":{"rendered":"<p>\u5c0f\u7a0b\u5e8f\u7684\u90e8\u5206\u63a5\u53e3\u9700\u8981\u7ecf\u8fc7\u7528\u6237\u6388\u6743\u540c\u610f\u624d\u80fd\u8c03\u7528\u3002\u6388\u6743\u529f\u80fd\u5b9e\u73b0\uff0c\u662f\u4e00\u4e2a\u4e0d\u53ef\u56de\u907f\uff0c\u53c8\u6709\u70b9\u626f\u4e0d\u6e05\u7684\u8bdd\u9898\uff0c\u8fd9\u91cc\u6211\u4eec\u505a\u4e00\u4e2a\u8be6\u7ec6\u6df1\u5165\u7684\u5206\u6790\u3002 <br \/>\n\u6700\u65b0\u7684\u5c0f\u7a0b\u5e8f\u5404\u79cd\u6388\u6743\uff0c\u6309\u4f7f\u7528\u8303\u56f4\u5206\u6210\u4e86\u591a\u4e2a<code>scope<\/code>\uff0c\u8be6\u7ec6\u7684<code>scope<\/code>\uff0c\u53ef\u4ee5\u53c2\u770b\u5c0f\u7a0b\u5e8f\u5b98\u65b9\u6587\u6863\uff0c\u8fd9\u91cc\u6211\u4eec\u5c31\u4e0d\u8d58\u8bc9\u4e86\u3002\u5730\u5740\u5982\u4e0b\uff1a <br \/>\n<a href=\"https:\/\/developers.weixin.qq.com\/miniprogram\/dev\/framework\/open-ability\/authorize.html\">https:\/\/developers.weixin.qq.com\/miniprogram\/dev\/framework\/open-ability\/authorize.html<\/a> <br \/>\n\u5176\u4e2d\uff0c<code>scope.userInfo<\/code> \u7528\u6237\u4fe1\u606f\u6388\u6743\uff0c\u7528\u6cd5\u6bd4\u8f83\u7279\u6b8a\uff0c\u6211\u4eec\u4e0b\u4e00\u8282\u518d\u4f5c\u8bb2\u89e3\u3002 <br \/>\n\u6211\u8fd9\u91cc\u5148\u628a<code>scope.userInfo<\/code>\u4e4b\u5916\u7684\u5176\u4ed6\u6388\u6743\u65b9\u6cd5\u57fa\u672c\u4e00\u81f4\u7684\u505a\u4e00\u4e2a\u8be6\u7ec6\u7684\u63a2\u8ba8\u3002<\/p>\n<p><strong>\u8be6\u7ec6\u5b8c\u6210\u6388\u6743\u6b65\u9aa4\u5982\u4e0b\uff1a<\/strong><\/p>\n<h3 id=\"\u4e00\u3001\u4f7f\u7528[wx.openSetting]\u83b7\u53d6\u6388\u6743\u72b6\u6001\">\u4e00\u3001\u4f7f\u7528[wx.openSetting]\u83b7\u53d6\u6388\u6743\u72b6\u6001<\/h3>\n<p>\u5b98\u65b9\u6587\u6863\uff1a<a href=\"https:\/\/developers.weixin.qq.com\/miniprogram\/dev\/api\/wx.getSetting.html\">https:\/\/developers.weixin.qq.com\/miniprogram\/dev\/api\/wx.getSetting.html<\/a><\/p>\n<p>\u5b98\u65b9\u793a\u4f8b\uff1a<\/p>\n<div>\n<pre><code>wx.getSetting({\n  success(res) {\n    console.log(res.authSetting)\n    \/\/ res.authSetting = {\n    \/\/   \"scope.userInfo\": true,\n    \/\/   \"scope.userLocation\": true\n    \/\/ }\n  }\n})<\/code><\/pre>\n<\/div>\n<p><strong>\u6ce8\u610f\uff1a<\/strong> <br \/>\n\u4e0a\u9762\u793a\u4f8b\u5b98\u65b9\u5e76\u6ca1\u6709\u8be6\u7ec6\u8bb2\u89e3\uff0c\u8fd4\u56de\u7684<code>res.authSetting<\/code>\u4e2d\uff0c\u6bcf\u4e00\u4e2a\u5177\u4f53\u7684<code>scope<\/code>\u6388\u6743\uff0c\u5176\u5b9e\u5e76\u4e0d\u662f<code>true<\/code>\u548c<code>false<\/code>\u90a3\u4e48\u7b80\u5355\u3002 <br \/>\n\u8fd4\u56de\u7684\u8be6\u7ec6\u7ed3\u679c\u53ef\u80fd\u5982\u4e0b\uff1a<\/p>\n<div>\n<pre><code>{\nerrMsg:\"getSetting:ok\"\uff0c\n    authSetting:{\n        scope.userInfo:true\n    }\n}<\/code><\/pre>\n<\/div>\n<p>\u751a\u81f3\u53ef\u80fd\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<div>\n<pre><code>{\nerrMsg:\"getSetting:ok\"\uff0c\n    authSetting:{}\n}<\/code><\/pre>\n<\/div>\n<p>\u9664\u4e86<code>errMsg<\/code>\u4fe1\u606f\u5916\uff0c\u6211\u4eec\u5173\u6ce8\u7684\u91cd\u70b9\u662f\u5728<code>authSetting<\/code>\u4e2d\u53bb\u53d6\u6211\u4eec\u60f3\u8981\u7684\u503c\uff0c\u4f46\u662f\uff0c\u6211\u4eec\u53d1\u73b0\uff0c\u53ef\u80fd\u6211\u4eec\u60f3\u8981\u7684\u7ed3\u679c\u5e76\u6ca1\u6709\u5728\u91cc\u9762\uff0c\u6240\u4ee5\u8fd9\u91cc\u5c31\u662f\u6211\u4eec\u5904\u7406\u6388\u6743\u7684\u5173\u952e\u4e86\u3002 <br \/>\n\u6240\u4ee5\uff0c\u5728\u5224\u65ad\u662f\u5426\u6388\u6743\u7684\u8fd9\u4e00\u6b65\u4e2d\uff0c\u6211\u4eec\u8981\u505a\u7684\u5de5\u4f5c\u5982\u4e0b\uff1a<\/p>\n<blockquote>\n<ul>\n<li>\u5224\u65ad\u6388\u6743\u6211\u4eec\u60f3\u8981\u7684<code>scope<\/code>\u662f\u5426\u5b58\u5728\uff1b\n<ul>\n<li>\u518d\u5224\u65ad\u662f<code>true<\/code>\u8fd8\u662f<code>false<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/blockquote>\n<p><strong>\u8fd9\u4e00\u6b65\u4e2d\uff1a<\/strong><\/p>\n<blockquote>\n<ul>\n<li><code>scope<\/code>\u4e3a\u7a7a\uff0c\u8868\u793a\u6388\u6743\u72b6\u6001\u4e3a\u521d\u59cb\u72b6\u6001\uff0c\u6b64\u65f6\uff0c\u53ef\u8c03\u8d77\u81ea\u52a8\u5f39\u7a97\uff0c\u8ba9\u7528\u6237\u6388\u6743\uff1b\n<ul>\n<li><code>scope<\/code>\u4e3a<code>trues<\/code>\uff0c\u8868\u793a\u7528\u6237\u5df2\u6388\u6743\uff0c\u5982\u4e3a<code>falses<\/code>\uff0c\u5219\u8868\u793a\u7528\u6237\u62d2\u7edd\u4e86\u6388\u6743\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/blockquote>\n<p>\u800c\u5c0f\u7a0b\u5e8f\u6388\u6743\u529f\u80fd\u7684\u6838\u5fc3\u903b\u8f91\u662f\u8fd9\u6837\u7684\uff0c <br \/>\n<strong>\u91cd\u70b9\u7684\u91cd\u70b9<\/strong>\uff1a<\/p>\n<blockquote>\n<p>\u5c0f\u7a0b\u5e8f\u5728\u7b2c\u4e00\u6b21\u8c03\u8d77\u6388\u6743\u4e4b\u540e\uff08\u81ea\u52a8\u5f39\u7a97\uff09\uff0c\u5982\u679c\u7528\u6237\u62d2\u7edd\u4e86\u6388\u6743\uff0c\u4e5f\u5c31\u662f\u4e0a\u9762\u8fd4\u56de\u7684\u7ed3\u679c\u4e3afalse\u7684\u8bdd\uff0c\u6211\u4eec\u60f3\u8981\u91cd\u65b0\u518d\u8c03\u8d77\uff08\u81ea\u52a8\u5f39\u7a97\uff09\uff0c\u9700\u8981\u7528\u6237\u81ea\u5df1\u624b\u52a8\u5220\u9664\u7a0b\u5e8f\uff0c\u6216\u8005\u662f\u9000\u51fa\u5c0f\u7a0b\u5e8f\uff0c\u7b49\u5f85\u4e00\u6bb5\u65f6\u95f4\u518d\u8fdb\u53bb\u624d\u80fd\u518d\u6b21\u8c03\u8d77\u6388\u6743\uff08\u81ea\u52a8\u5f39\u7a97\uff09\uff0c\u8fd9\u79cd\u65b9\u5f0f\uff0c\u660e\u663e\u662f\u4e00\u79cd\u4e0d\u53ef\u53d6\u7684\u7528\u6237\u4f53\u9a8c\u6781\u5dee\u7684\u65b9\u6cd5\u3002<\/p>\n<\/blockquote>\n<p>\u5e78\u597d\uff0c\u5b98\u65b9\u6709\u4e00\u4e2a\u7528\u6237\u53ef\u4ee5\u8bbe\u7f6e\u6240\u6709\u6388\u6743\u7684\u9875\u9762\uff0c\u4e5f\u5c31\u662f<code>wx.openSetting<\/code>\u63a5\u53e3\u3002<\/p>\n<p>\u8be5\u529f\u80fd\u5982\u4e0b\u56fe\uff1a <br \/>\n<img decoding=\"async\" src=\"https:\/\/img.chenbing.name\/uploads\/2019\/03\/b830d2136768c7ec952f110a49a9aa59_f46c499c-8a0b-4950-888f-fd3cba9db80e.jpg\" alt=\"![\" title=\"\">](08ac31c3-c38f-48c8-a13e-763ab5b4f9f3_files\/2a051386-862b-4004-bbe0-59b710d177f4.png)<\/p>\n<p>\u6240\u4ee5\uff0c\u5230\u8fd9\u91cc\u660e\u767d\u4e86\u6574\u4e2a\u6388\u6743\u7684\u903b\u8f91\u540e\uff0c\u8be5\u600e\u4e48\u5b9e\u73b0\u5b8c\u6574\u7684\u6388\u6743\u529f\u80fd\uff0c\u6211\u4eec\u5fc3\u91cc\u5c31\u6709\u6570\u4e86\u3002<\/p>\n<h3 id=\"\u4e8c\u3001\u4f7f\u7528wx.openSetting\u914d\u5408\u5b8c\u6210\u6388\u6743\">\u4e8c\u3001\u4f7f\u7528 wx.openSetting \u914d\u5408\u5b8c\u6210\u6388\u6743<\/h3>\n<p>\u5b9e\u73b0\u6388\u6743\u529f\u80fd\u7684\u903b\u8f91\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528[wx.openSetting]\u83b7\u53d6\u6388\u6743\u72b6\u6001\n<ul>\n<li>\u7ed3\u679c\u4e3a\u7a7a &#8212; \u4f7f\u7528 <code>wx.authorize<\/code>\u5f39\u51fa\u6388\u6743<\/li>\n<li>\u7ed3\u679c\u4e3afalse &#8212; \u5f39\u7a97\u8fdb\u884c\u8bf4\u660e\uff0c\u5f15\u5bfc\u7528\u6237\u5230\u6743\u9650\u8bbe\u7f6e\u9875\u9762\uff08\u5f39\u7a97\u53ef\u4f7f\u7528<code>wx.showModal<\/code>\uff0c\u53bb\u8bbe\u7f6e\u9875\u4f7f\u7528<code>wx.openSetting<\/code>\uff09<\/li>\n<li>\u7ed3\u679c\u4e3atrue &#8212; \u7528\u6237\u5df2\u6388\u6743\uff0c\u6b63\u5e38\u8fdb\u884c\u81ea\u5df1\u7684\u4e1a\u52a1\u903b\u8f91\u5373\u53ef\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3 id=\"\u4e09\u3001\u5b8c\u6574\u5b9e\u4f8b\u4ee3\u7801\uff1a\">\u4e09\u3001\u5b8c\u6574\u5b9e\u4f8b\u4ee3\u7801\uff1a<\/h3>\n<p>\u8fd9\u91cc\u4ee5\u4f4d\u7f6e\u6388\u6743\u4e3a\u4f8b\uff1a<\/p>\n<div data-mode=\"javascript\">\n<pre><code>  \/\/\u5728\u5730\u56fe\u4f4d\u7f6e\u9009\u62e9\n  chooseLocation(){\n    const that = this\n\n    wx.getSetting({\n      success(res){\n        console.log(res)\n        console.log(res.authSetting['scope.userLocation'])\n\n        if(res.authSetting['scope.userLocation'] ===''){\n\n          wx.authorize({\n            scope: 'scope.userLocation',\n            success() {\n\n              \/\/\u8c03\u7528\u5730\u56fe\u7684\u67e5\u8be2\u4f4d\u7f6e\u529f\u80fd\n              \/\/doSomeThing()\n\n            }\n          })\n\n\n        }else if(res.authSetting['scope.userLocation'] === false){\n\n          wx.showModal({\n\n            title: '\u63d0\u793a',\n            content: '\u9700\u8981\u5141\u8bb8\u4f7f\u7528\u5730\u7406\u4f4d\u7f6e\u6743\u9650\uff0c\u8bf7\u70b9\u51fb\u201c\u786e\u5b9a\u201d\u53bb\u6388\u6743\u540e\u518d\u4f7f\u7528\u4f4d\u7f6e\u3002',\n            success(res) {\n              if (res.confirm) {\n                console.log('\u7528\u6237\u70b9\u51fb\u786e\u5b9a')\n\n                wx.openSetting({\n                  success(res) {\n                    console.log(res.authSetting)\n\n                  }\n                })\n\n              } else if (res.cancel) {\n                console.log('\u7528\u6237\u70b9\u51fb\u53d6\u6d88')\n              }\n            }\n\n          })\n\n        }else{\n\n          \/\/\u8c03\u7528\u5730\u56fe\u7684\u67e5\u8be2\u4f4d\u7f6e\u529f\u80fd\n          \/\/doSomeThing()\n\n        }\n\n      }\n    })\n\n\n  },\n<\/code><\/pre>\n<\/div>\n<p>ps:\u6700\u65b0\u4f4d\u7f6e\u6388\u6743\uff0c\u9700\u8981\u5728app.json\u505a\u7528\u9014\u58f0\u660e\uff0c\u5982\u4e0b\u4ee3\u7801\u6700\u540e\u7684<code>permission<\/code>&#8220;`\u8282\u70b9\u7533\u660e\uff0c\u8be6\u7ec6\u4f60\u67e5\u9605\u5b98\u65b9\u6587\u6863\uff1a <br \/>\n<a href=\"https:\/\/developers.weixin.qq.com\/miniprogram\/dev\/framework\/config.html#permission\">https:\/\/developers.weixin.qq.com\/miniprogram\/dev\/framework\/config.html#permission<\/a><\/p>\n<div data-mode=\"json\">\n<pre><code>{\n  \"pages\":[\n   \u2026\u2026\n  ],\n  \"window\":{\n    \"backgroundTextStyle\":\"light\",\n    \"navigationBarBackgroundColor\": \"#fff\",\n    \"navigationBarTitleText\": \"WeChat\",\n    \"navigationBarTextStyle\":\"black\",\n      \"navigationStyle\": \"default\"\n  },\n\n  \"tabBar\": {\n    \u2026\u2026\n  },\n\n  \"permission\": {\n    \"scope.userLocation\": {\n      \"desc\": \"\u4f60\u7684\u4f4d\u7f6e\u4fe1\u606f\u5c06\u7528\u4e8e\u5bfc\u822a\u7ebf\u8def\u5c55\u793a\"\n    }\n  }\n\n}<\/code><\/pre>\n<\/div>\n<p><wiz_tmp_tag id=\"wiz-table-range-border\" contenteditable=\"false\" style=\"display: none;\"><\/p>\n<div id=\"wiz-table-col-line\" style=\"display: none;\"><\/div>\n<div id=\"wiz-table-row-line\" style=\"display: none;\"><\/div>\n<div id=\"wiz-table-range-border_start\" style=\"display: none;\">\n<div id=\"wiz-table-range-border_start_top\"><\/div>\n<div id=\"wiz-table-range-border_start_right\"><\/div>\n<div id=\"wiz-table-range-border_start_bottom\"><\/div>\n<div id=\"wiz-table-range-border_start_left\"><\/div>\n<div id=\"wiz-table-range-border_start_dot\"><\/div>\n<\/div>\n<div id=\"wiz-table-range-border_range\" style=\"display: none;\">\n<div id=\"wiz-table-range-border_range_top\"><\/div>\n<div id=\"wiz-table-range-border_range_right\"><\/div>\n<div id=\"wiz-table-range-border_range_bottom\"><\/div>\n<div id=\"wiz-table-range-border_range_left\"><\/div>\n<div id=\"wiz-table-range-border_range_dot\"><\/div>\n<\/div>\n<p><\/wiz_tmp_tag><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c0f\u7a0b\u5e8f\u7684\u90e8\u5206\u63a5\u53e3\u9700\u8981\u7ecf\u8fc7\u7528\u6237\u6388\u6743\u540c\u610f\u624d\u80fd\u8c03\u7528\u3002\u6388\u6743\u529f\u80fd\u5b9e\u73b0\uff0c\u662f\u4e00\u4e2a\u4e0d\u53ef\u56de\u907f\uff0c\u53c8\u6709\u70b9\u626f\u4e0d\u6e05\u7684\u8bdd\u9898\uff0c\u8fd9\u91cc\u6211\u4eec\u505a\u4e00\u4e2a\u8be6\u7ec6\u6df1\u5165\u7684\u5206\u6790\u3002 \u6700\u65b0\u7684\u5c0f\u7a0b\u5e8f\u5404\u79cd\u6388\u6743\uff0c\u6309\u4f7f\u7528\u8303\u56f4\u5206\u6210\u4e86\u591a\u4e2ascope\uff0c\u8be6\u7ec6\u7684scope\uff0c\u53ef\u4ee5\u53c2\u770b\u5c0f\u7a0b\u5e8f\u5b98\u65b9\u6587\u6863\uff0c\u8fd9\u91cc\u6211\u4eec\u5c31\u4e0d\u8d58\u8bc9\u4e86\u3002\u5730\u5740\u5982\u4e0b\uff1a https:\/\/developers.weixin.qq.com\/miniprogram\/dev\/fra&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[87,4],"tags":[28,64,65],"class_list":["post-401","post","type-post","status-publish","format-standard","hentry","category-wechat_mimapp","category-skill","tag-28","tag-64","tag-65"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/posts\/401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/comments?post=401"}],"version-history":[{"count":1,"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/posts\/401\/revisions"}],"predecessor-version":[{"id":696,"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/posts\/401\/revisions\/696"}],"wp:attachment":[{"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/media?parent=401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/categories?post=401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/tags?post=401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}