Skip to content

Commit

Permalink
Merge pull request #61 from Yuntun-Study-Longue/master
Browse files Browse the repository at this point in the history
defaultopenTagList support
  • Loading branch information
JasonBoy authored Feb 26, 2021
2 parents ad178b3 + 3a8cb38 commit a5876b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ let defaultScriptUrl = '//res.wx.qq.com/open/js/jweixin-1.4.0.js';
//default apis with share-on-moment and share-on-chat
const defaultApiList = ['onMenuShareTimeline', 'onMenuShareAppMessage'];

// default opentags wx-open-subscribe and wx-open-audio
const defaultopenTagList = ['wx-open-subscribe', 'wx-open-audio'];

class WechatJSSDK {
/**
* Initialize the WechatJSSDK instance
Expand All @@ -36,6 +39,7 @@ class WechatJSSDK {
this.sdkUrl = this.config.customUrl;
}
let apiList = this.config.jsApiList;
let tagList = this.config.openTagList;
//add more apis if passed in
if (!apiList || apiList.length <= 0) {
this.config.jsApiList = defaultApiList;
Expand All @@ -49,6 +53,19 @@ class WechatJSSDK {
}
}
}
//add more tags if passed in
if (!tagList || tagList.length <= 0) {
this.config.openTagList = defaultopenTagList;
} else {
let i = 0;
const length = defaultopenTagList.length;
for (; i < length; i++) {
const defaultItem = defaultopenTagList[i];
if (tagList.indexOf(defaultItem) < 0) {
tagList.push(defaultItem);
}
}
}
this.debug = !!this.config.debug;
return this;
}
Expand Down Expand Up @@ -79,6 +96,10 @@ class WechatJSSDK {
nonceStr: config.nonceStr || selfConfig.nonceStr,
signature: config.signature || selfConfig.signature,
jsApiList: selfConfig.jsApiList.slice(0, selfConfig.jsApiList.length),
openTagList: selfConfig.openTagList.slice(
0,
selfConfig.openTagList.length
),
};
const debug = this.debug;
return new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wechat-jssdk",
"version": "5.0.6",
"version": "5.0.7",
"description": "Next-Generation WeChat JS-SDK integration with NodeJS",
"main": "./lib/index.js",
"source": "./lib/client.js",
Expand Down

0 comments on commit a5876b1

Please sign in to comment.