wxAuth.js 545B

12345678910111213141516171819202122232425
  1. import Taro from '@tarojs/taro'
  2. // https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html
  3. /**
  4. * 微信授权
  5. * @param {*} scope
  6. */
  7. export function authorize(scope) {
  8. return new Promise((resolve, reject) => {
  9. Taro.getSetting({
  10. success: function (res) {
  11. if (!res.authSetting[scope]) {
  12. Taro.authorize({
  13. scope,
  14. success: resolve,
  15. fail: reject,
  16. })
  17. } else {
  18. resolve()
  19. }
  20. },
  21. fail: reject,
  22. })
  23. })
  24. }