getSetting.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //订阅模板消息函数
  2. /* tmplId 参数传数组 callback 回调函数*/
  3. function Setting(tmplId,callback){
  4. uni.getSetting({
  5. withSubscriptions: true,
  6. success(res) {
  7. var itemSettings = res.subscriptionsSetting.itemSettings?res.subscriptionsSetting.itemSettings:"";
  8. console.log("订阅模板消息列表"+JSON.stringify(res))
  9. if (itemSettings) {
  10. if (itemSettings[tmplId]=='accept') {
  11. // 已授权过不再显示
  12. console.log('is accredit:ok')
  13. }else{
  14. //未授权唤起授权
  15. uni.requestSubscribeMessage({
  16. tmplIds: tmplId,
  17. success (res) {
  18. console.log(res)
  19. // reject 表示取消授权
  20. if(res[tmplId] === 'reject'){}
  21. // accept 表示授权
  22. if(res[tmplId] === 'accept'){
  23. }
  24. }
  25. })
  26. }
  27. }else{
  28. uni.requestSubscribeMessage({
  29. tmplIds: tmplId,
  30. success (res) {
  31. console.log(res)
  32. // reject 表示取消授权
  33. if(res[tmplId] === 'reject'){}
  34. // accept 表示授权
  35. if(res[tmplId] === 'accept'){}
  36. }
  37. })
  38. }
  39. }
  40. })
  41. }