Applet user authorization process

1. Get the delivery address micro-channel (process allow authorized users, authorization denied in all cases)

getAddress: function () {
       var T = the this ; 
      wx.getSetting ({ 
        Success (RES) { 
          the console.log ( "vres.authSetting [ 'scope.address']:", res.authSetting [ 'scope.address' ])
           var OpenID = wx.getStorageSync ( "OpenID" ); 
          the console.log (OpenID); 
          // the current user settings in the user authorization result, determines whether or not authorized shipping address contains 
          // user is authorized to use the delivery address 
          iF (RES .authSetting [ 'scope.address' ]) { 
            the console.log ( "111" )
             // select shipping address 
            wx.chooseAddress ({ chooseAddress({
              success(res) {
                app.util.request({
                  url: "entry/wxapp/Member_address",
                  header: {
                    "content-type": "application/x-www-form-urlencoded"
                  },
                  data: {
                    username: res.userName,
                    postalcode: res.postalCode,
                    provincename: res.provinceName,
                    cityname: res.cityName,
                    countyname: res.countyName,
                    detailinfo: res.detailInfo,
                    telnumber: res.telNumber,
                    openid: openid
                  },
                  Success: function (RES) { 
                    the console.log ( 'success 2' , RES); 
                    t.setData ({ 
                      NOADDRESS: to false 
                    }) 
                    wx.setStorage ({ 
                      Key: 'NOADDRESS' , 
                      Data: t.data.noAddress, 
                    }) 
                  } 
                }); 
              } 
            }) 
            // user does not agree to use the applet address 
          } the else { 
            the console.log ( '222' );
             //Cancellation been authorized shipping address calling wx.openSetting (), invoking client applet settings interface allows the user to Open Authorization
             if(res.authSetting [ 'scope.address'] == to false ) { 
              wx.openSetting ({ 
                Success (RES) { 
                  the console.log ( '333' ); 
                  the console.log (res.authSetting) 
                } 
              }) 
            } the else {
               / / user current setting authorization does not include the delivery address (note is first opened obtain user authorization information, shipping address), call wx.chooseAddress (), acquires the user shipping address 
              the console.log ( '444' ); 
              WX. chooseAddress ({ 
                Success (RES) { 
                  app.util.request ({ 
                    URL: "entry / wxApp / Member_address" ,
                    header: {
                      "content-type": "application/x-www-form-urlencoded"
                    },
                    data: {
                      username: res.userName,
                      postalcode: res.postalCode,
                      provincename: res.provinceName,
                      cityname: res.cityName,
                      countyname: res.countyName,
                      detailinfo: res.detailInfo,
                      telnumber: res.telNumber,
                      openid: openid
                    },
                    success: (res)=> {
                      console.log('成功1',res);
                      t.setData({
                        noAddress: false
                      })
                      wx.setStorage({
                        key: 'noAddress',
                        data: t.data.noAddress,
                      })
                    }
                  });
                }
              })
            }
          }
        }
      })
    }

2. Get authorized camera (allowing the user process, the case denied)

Achieve results:

(1) first entered, invoking the authorization query box

 

 

(2) If the user rejects the display alert box

(3) If the authorized user, invoking client applet settings interface

 

 

wxml Code

<camera wx:if="{{camera}}" device-position="back" flash="off" binderror="error" class='camera_box'></camera>

js code

// user refused to authorize cameras 
  error: function () { 
    wx.showModal ({ 
      title: 'warning' , 
      Content: 'If not authorize the use of the camera, you can not use the camera recognition!' , 
      CancelText: 'not authorized' , 
      cancelColor: '# 1ba9ba' , 
      confirmText: 'authorize' , 
      confirmColor: '# 1ba9ba' , 
      Success (RES) { 
        // allows opening authorization page 
        IF (res.confirm) {
           // invoking client applet interface settings, user settings return the operation result 
          wx.openSetting ({ 
            Success (RES) { 
              res.authSetting ={
                 "Scope.camera": to true 
              } 
            }, 
            Fail (ERR) { 
              the console.log ( 'ERR' , ERR); 
            } 
          }) 
        } the else  IF (res.cancel) { // refuse to open authorization page 
          wx.redirectTo ({ 
            URL: '../selcat/selcat' , 
          }) 
        } 
      } 
    }) 
  }

Added: projects, re-authorization can not transfer from the camera and get the shipping address with the same logic, mainly because wx.openSetting API must click to call

 

 

Details, search applet "junk where to go."

Guess you like

Origin www.cnblogs.com/duanzhenzhen/p/11404077.html