亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Table of Contents
1. Permission interface
2、授權(quán)案例
Home WeChat Applet Mini Program Development Summarize and organize WeChat applet permission interfaces

Summarize and organize WeChat applet permission interfaces

May 16, 2022 am 11:43 AM
WeChat applet

This article brings you related issues about WeChat Mini Program. It mainly introduces the relevant content of the permission interface in the WeChat Mini Program, including the user authorization interface and obtaining user permission settings. interface, opening the user permission setting interface, etc. Let’s take a look at it together. I hope it will be helpful to everyone.

Summarize and organize WeChat applet permission interfaces

【Related learning recommendations: 小program learning tutorial

1. Permission interface

?Some interfaces are required It can be called only after user authorization. We divide these interfaces into multiple scopes according to their usage scope. The user chooses to authorize the scope. After authorizing a scope, all its corresponding interfaces can be used directly. When such interfaces are called:

  • If the user does not accept or rejects this permission, a pop-up window will pop up to ask the user, and the user can only call the interface after clicking Unify.
  • If the user is authorized, the interface can be called directly.
  • If the user has refused authorization, the pop-up window will not appear, but will directly enter the interface fail callback.

?The corresponding relationship between the object scope fields in the permissions of this type of interface and the interface is as shown in the following table.

##scope.userLocationBackgroundwx. startLocationUpdateBackgroundBackground locationscope.recordwx.startRecord, wx.joinVoIPChat, RecorderManager.startMicrophonescope.cameracamera component, wx.createVKSessionCamerascope.bluetoothwx.openBluetoothAdapter, wx.createBLEPeripheralServerBluetoothscope.writePhotosAlbumwx.saveImageToPhotosAlbum, wx.saveVideoToPhotosAlbumAdd to albumscope.addPhoneContactwx.wx.addPhoneContactAdd to contactscope.addPhoneCalendarwx.addPhoneRepeatCalendar, wx.addPhoneCalendarAdd to calendarscope.werunwx. getWeRunDataWeChat exercise stepsscope.addresswx.chooseAddressCorrespondence address (authorization has been cancelled, you can directly Call the corresponding interface) scope.invoiceTitlewx.chooseInvoiceTitleInvoice header (authorization has been cancelled, you can directly call the corresponding interface)scope.invoicewx.chooseInvoiceGet the invoice (authorization has been cancelled, you can directly call the corresponding interface)scope.userInfowx.getUserInfoUser information (the mini program has been recycled, please fill it in with your avatar nickname, and the mini game can continue to be called)

? The mini program provides three sets of interfaces to perform corresponding operations on interface permissions: wx.getSetting()Get the user’s current authorization status; wx.openSetting()Open the setting interface To guide the user to enable authorization; wx.authorize()Change the authorization status.

1.1 User authorization interfacewx.authorize(Object object)

Initiate an authorization request to the user in advance. After calling this interface, a pop-up window will immediately ask the user whether they agree to authorize the applet to use a certain function or obtain some of the user's data, but the corresponding interface will not actually be called. If the user has previously agreed to the authorization, no pop-up window will appear and success will be returned directly. The properties are shown in the table below.

scope Corresponding interface Description
scope .userLocation wx.getLocation, wx.chooseLocation, wx.startLocationUpdate Geolocation
##NoCallback function that fails to call the interface completefunctionNoThe callback function that ends the interface call (call Both success and failure will be executed)
Attribute Type Default value Required Description
scope #string
is the scope that needs to obtain permissions for. See the scope list for details
success function
No The interface call was successful Callback function
fail function

?Sample code from the official website:

//?可以通過?wx.getSetting?先查詢一下用戶是否授權(quán)了?"scope.record"?這個?scopewx.getSetting({
??success(res)?{
????if?(!res.authSetting['scope.record'])?{
??????wx.authorize({
????????scope:?'scope.record',
????????success?()?{
??????????//?用戶已經(jīng)同意小程序使用錄音功能,后續(xù)調(diào)用?wx.startRecord?接口不會彈窗詢問
??????????wx.startRecord()
????????}
??????})
????}
??}})
1.2 Get user permission setting interface

wx.getSetting(Object object)

?This interface obtains the user's current settings. Only the permissions that the applet has requested from the user will appear in the return value. The attributes are as follows:

AttributeTypeDefault valueRequiredDescriptionMinimum version##withSubscriptionssuccessCallback function for successful interface call failfunctionCallback function for failed interface callfunctionNoobject.success callback function is as follows:
Boolean false No Whether to obtain the subscription status of the user's subscription message at the same time, it is not obtained by default. Note: withSubscriptions only returns subscription messages for which the user has checked "Always keep the above selection and never ask again" in the subscription panel. 2.10.1
function ##No

No

##complete

The callback function at the end of the interface call (will be executed if the call is successful or failed)

AttributeTypeauthSettingAuthSettingSubscriptionsSettingwithSubscriptionstrueAuthSetting
Description Minimum version
User authorization result
subscriptionsSetting
User subscription message settings, the interface parameter will be returned only when the value is . 2.10.1 miniprogramAuthSetting
When called in the plug-in, the user authorization result of the current host applet

??官網(wǎng)示例代碼:

wx.getSetting({
??success?(res)?{
????console.log(res.authSetting)
????//?res.authSetting?=?{
????//???"scope.userInfo":?true,
????//???"scope.userLocation":?true
????//?}
??}})

1.3 打開用戶權(quán)限設(shè)置接口wx.openSetting(Object object)

??該接口調(diào)用客戶端小程序設(shè)置界面,返回用戶設(shè)置的操作結(jié)果。設(shè)置界面只會出現(xiàn)小程序已經(jīng)向用戶請求過的權(quán)限。

屬性 類型 默認值 必填 說明 最低版本
withSubscriptions Boolean false 是否同時獲取用戶訂閱消息的訂閱狀態(tài),默認不獲取。注意:withSubscriptions 只返回用戶勾選過訂閱面板中的“總是保持以上選擇,不再詢問”的訂閱消息。 2.10.3
success function
接口調(diào)用成功的回調(diào)函數(shù)
fail function
接口調(diào)用失敗的回調(diào)函數(shù)
complete function
接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

object.success回調(diào)函數(shù)如下:

屬性 類型 說明 最低版本
authSetting AuthSetting 用戶授權(quán)結(jié)果
subscriptionsSetting SubscriptionsSetting 用戶訂閱消息設(shè)置,接口參數(shù)withSubscriptions值為true時才會返回。 2.10.3
  • 注意:2.3.0 版本開始,用戶發(fā)生點擊行為后,才可以跳轉(zhuǎn)打開設(shè)置頁,管理授權(quán)信息。

??官網(wǎng)示例代碼:

wx.openSetting({
??success?(res)?{
????console.log(res.authSetting)
????//?res.authSetting?=?{
????//???"scope.userInfo":?true,
????//???"scope.userLocation":?true
????//?}
??}})

2、授權(quán)案例

??本例使用獲取地理位置接口wx.getLocation()和開始錄音接口wx.startRecord()進行相關(guān)操作,而這兩個接口都需要設(shè)置操作權(quán)限。

Setting.wxml代碼如下:

<!--index.wxml--><view>獲取地理位置</view><view>{{context}}</view><view>開始錄音</view>

Setting.js代碼如下:

//index.js//獲取應(yīng)用實例const?app?=?getApp()Page({
??data:?{
???
??},
??
??onLoad:?function?()?{
????context:''
??},
??location1:function(){	//獲取地理位置
????var?that=this
????wx.getSetting({	//獲取用戶權(quán)限設(shè)置接口
??????success(res)?{
????????console.log(res)
????????if?(!res.authSetting['scope.userLocation'])?{
??????????wx.authorize({		//授權(quán)
????????????scope:?'scope.userLocation',	//地理位置權(quán)限,看線上面的scope對應(yīng)的參數(shù)
????????????success()?{
??????????????wx.getLocation({		//獲取當(dāng)前的地理位置
????????????????success:?function(res)?{
?????????????????console.log(res)
??????????????????that.setData({?context:?"你所在的經(jīng)度是"?+?res.latitude+"你所在的緯度是"+res.longitude})
????????????????},
??????????????})
????????????}
??????????})
????????}
??????}
????})
??},
?
??location2:?function?()?{			//錄音
????var?that?=?this
??
????????wx.getSetting({
??????????success(res)?{
????????????console.log(res.authSetting)
????????????if?(!res.authSetting['scope.record'])?{
??????????????wx.openSetting({		//打開用戶權(quán)限設(shè)置界面
????????????????success(res)?{
??????????????????console.log(res)
??????????????????wx.startRecord({		//開始錄音
????????????????????success(res)?{
??????????????????????const?tempFilePath?=?res.tempFilePath
??????????????????????console.log("錄音結(jié)束")
????????????????????}
??????????????})
????????????}?
????????})
????????}}
????????})
??}})

?? location()1函數(shù)實現(xiàn)獲取地理位置的功能,該函數(shù)先調(diào)用wx.getSetting()接口獲取權(quán)限狀態(tài),然后調(diào)用wx.authorize()接口修改地理位置權(quán)限scope.userLocation。location2()函數(shù)實現(xiàn)錄音功能,該函數(shù)先調(diào)用wx.getSetting()接口獲取權(quán)限狀態(tài),然后調(diào)用wx.openSetting()接口打開錄音權(quán)限設(shè)置界面來修改錄音權(quán)限。從本例可以看出設(shè)置權(quán)限的時候應(yīng)該先調(diào)用wx.getSetting()接口來修改權(quán)限狀態(tài),在沒有權(quán)限打開的情況下可以調(diào)用wx.authorize()接口或者wx.openSetting()接口來修改權(quán)限狀態(tài),wx.authorize()接口不出現(xiàn)修改權(quán)限的操作權(quán)限,而wx.openSetting()接口會出現(xiàn)修改權(quán)限的操作界面。

??案例效果如下:

Summarize and organize WeChat applet permission interfaces

??點擊獲取地理位置:

Summarize and organize WeChat applet permission interfaces

??點擊允許之后會顯示當(dāng)前所在的經(jīng)緯度。

Summarize and organize WeChat applet permission interfaces

??點擊開始錄音按鈕出現(xiàn)麥克風(fēng)授權(quán):

Summarize and organize WeChat applet permission interfaces

【相關(guān)學(xué)習(xí)推薦:小程序?qū)W習(xí)教程

The above is the detailed content of Summarize and organize WeChat applet permission interfaces. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Xianyu WeChat mini program officially launched Xianyu WeChat mini program officially launched Feb 10, 2024 pm 10:39 PM

Xianyu's official WeChat mini program has quietly been launched. In the mini program, you can post private messages to communicate with buyers/sellers, view personal information and orders, search for items, etc. If you are curious about what the Xianyu WeChat mini program is called, take a look now. What is the name of the Xianyu WeChat applet? Answer: Xianyu, idle transactions, second-hand sales, valuations and recycling. 1. In the mini program, you can post idle messages, communicate with buyers/sellers via private messages, view personal information and orders, search for specified items, etc.; 2. On the mini program page, there are homepage, nearby, post idle, messages, and mine. 5 functions; 3. If you want to use it, you must activate WeChat payment before you can purchase it;

Implement image filter effects in WeChat mini programs Implement image filter effects in WeChat mini programs Nov 21, 2023 pm 06:22 PM

Implementing picture filter effects in WeChat mini programs With the popularity of social media applications, people are increasingly fond of applying filter effects to photos to enhance the artistic effect and attractiveness of the photos. Picture filter effects can also be implemented in WeChat mini programs, providing users with more interesting and creative photo editing functions. This article will introduce how to implement image filter effects in WeChat mini programs and provide specific code examples. First, we need to use the canvas component in the WeChat applet to load and edit images. The canvas component can be used on the page

Implement the drop-down menu effect in WeChat applet Implement the drop-down menu effect in WeChat applet Nov 21, 2023 pm 03:03 PM

To implement the drop-down menu effect in WeChat Mini Programs, specific code examples are required. With the popularity of mobile Internet, WeChat Mini Programs have become an important part of Internet development, and more and more people have begun to pay attention to and use WeChat Mini Programs. The development of WeChat mini programs is simpler and faster than traditional APP development, but it also requires mastering certain development skills. In the development of WeChat mini programs, drop-down menus are a common UI component, achieving a better user experience. This article will introduce in detail how to implement the drop-down menu effect in the WeChat applet and provide practical

What is the name of Xianyu WeChat applet? What is the name of Xianyu WeChat applet? Feb 27, 2024 pm 01:11 PM

The official WeChat mini program of Xianyu has been quietly launched. It provides users with a convenient platform that allows you to easily publish and trade idle items. In the mini program, you can communicate with buyers or sellers via private messages, view personal information and orders, and search for the items you want. So what exactly is Xianyu called in the WeChat mini program? This tutorial guide will introduce it to you in detail. Users who want to know, please follow this article and continue reading! What is the name of the Xianyu WeChat applet? Answer: Xianyu, idle transactions, second-hand sales, valuations and recycling. 1. In the mini program, you can post idle messages, communicate with buyers/sellers via private messages, view personal information and orders, search for specified items, etc.; 2. On the mini program page, there are homepage, nearby, post idle, messages, and mine. 5 functions; 3.

WeChat applet implements image upload function WeChat applet implements image upload function Nov 21, 2023 am 09:08 AM

WeChat applet implements picture upload function With the development of mobile Internet, WeChat applet has become an indispensable part of people's lives. WeChat mini programs not only provide a wealth of application scenarios, but also support developer-defined functions, including image upload functions. This article will introduce how to implement the image upload function in the WeChat applet and provide specific code examples. 1. Preparatory work Before starting to write code, we need to download and install the WeChat developer tools and register as a WeChat developer. At the same time, you also need to understand WeChat

Use WeChat applet to achieve carousel switching effect Use WeChat applet to achieve carousel switching effect Nov 21, 2023 pm 05:59 PM

Use the WeChat applet to achieve the carousel switching effect. The WeChat applet is a lightweight application that is simple and efficient to develop and use. In WeChat mini programs, it is a common requirement to achieve carousel switching effects. This article will introduce how to use the WeChat applet to achieve the carousel switching effect, and give specific code examples. First, add a carousel component to the page file of the WeChat applet. For example, you can use the &lt;swiper&gt; tag to achieve the switching effect of the carousel. In this component, you can pass b

Implement image rotation effect in WeChat applet Implement image rotation effect in WeChat applet Nov 21, 2023 am 08:26 AM

To implement the picture rotation effect in WeChat Mini Program, specific code examples are required. WeChat Mini Program is a lightweight application that provides users with rich functions and a good user experience. In mini programs, developers can use various components and APIs to achieve various effects. Among them, the picture rotation effect is a common animation effect that can add interest and visual effects to the mini program. To achieve image rotation effects in WeChat mini programs, you need to use the animation API provided by the mini program. The following is a specific code example that shows how to

Implement the sliding delete function in WeChat mini program Implement the sliding delete function in WeChat mini program Nov 21, 2023 pm 06:22 PM

Implementing the sliding delete function in WeChat mini programs requires specific code examples. With the popularity of WeChat mini programs, developers often encounter problems in implementing some common functions during the development process. Among them, the sliding delete function is a common and commonly used functional requirement. This article will introduce in detail how to implement the sliding delete function in the WeChat applet and give specific code examples. 1. Requirements analysis In the WeChat mini program, the implementation of the sliding deletion function involves the following points: List display: To display a list that can be slid and deleted, each list item needs to include

See all articles