wechatOfficialAccount.js 742 B

12345678910111213141516171819202122232425262728
  1. // 必须在用户点击的同步调用链内调用;打开主页不代表已经关注或绑定。
  2. export function openWechatOfficialAccount({ onUnavailable, onComplete }) {
  3. let settled = false
  4. const finish = (unavailable) => {
  5. if (settled) return
  6. settled = true
  7. try {
  8. if (unavailable) onUnavailable()
  9. } finally {
  10. onComplete()
  11. }
  12. }
  13. try {
  14. // #ifdef MP-WEIXIN
  15. if (typeof wx !== 'undefined' && typeof wx.openOfficialAccountProfile === 'function') {
  16. wx.openOfficialAccountProfile({
  17. username: 'gh_53e43e6f5c92',
  18. success: () => finish(false),
  19. fail: () => finish(true)
  20. })
  21. return
  22. }
  23. // #endif
  24. finish(true)
  25. } catch (error) {
  26. finish(true)
  27. }
  28. }