diff --git a/packages/cw/wechat_sdk_share/logics/index.js b/packages/cw/wechat_sdk_share/logics/index.js index 1d8c5c84..697187c7 100644 --- a/packages/cw/wechat_sdk_share/logics/index.js +++ b/packages/cw/wechat_sdk_share/logics/index.js @@ -14,6 +14,7 @@ import updateAppMessageShareData from './updateAppMessageShareData' import getNetworkType from './getNetworkType' import closeWindow from './closeWindow' import previewImage from './previewImage' +import sendTemplateMessage from './sendTemplateMessage' // LOGIC IMPORTS UtilsLogics.install = function (Vue, option = {}) { @@ -31,6 +32,7 @@ UtilsLogics.install = function (Vue, option = {}) { Vue.prototype.$library[`${$libraryName}`].getNetworkType=getNetworkType Vue.prototype.$library[`${$libraryName}`].closeWindow=closeWindow Vue.prototype.$library[`${$libraryName}`].previewImage=previewImage + Vue.prototype.$library[`${$libraryName}`].sendTemplateMessage=sendTemplateMessage // LOGIC USE } diff --git a/packages/cw/wechat_sdk_share/logics/sendTemplateMessage/api.yaml b/packages/cw/wechat_sdk_share/logics/sendTemplateMessage/api.yaml new file mode 100644 index 00000000..0af76592 --- /dev/null +++ b/packages/cw/wechat_sdk_share/logics/sendTemplateMessage/api.yaml @@ -0,0 +1,5 @@ +- name: sendTemplateMessage + description: 发送模版消息 + type: both + belong: logic + labels: [Runtime] diff --git a/packages/cw/wechat_sdk_share/logics/sendTemplateMessage/index.js b/packages/cw/wechat_sdk_share/logics/sendTemplateMessage/index.js new file mode 100644 index 00000000..e2eefa5b --- /dev/null +++ b/packages/cw/wechat_sdk_share/logics/sendTemplateMessage/index.js @@ -0,0 +1,41 @@ +/** + * @param {string} options 这是一个描述 + * @returns {string} result + */ +import wx from 'weixin-js-sdk' +export default (appId, nonceStr, signature, accessToken, openId, templateId, url, pagepath, value ) => { + var timestamp = Math.floor(new Date().getTime() / 1000).toString(); + + wx.config({ + debug: false, + appId, + timestamp, + nonceStr, + signature, + jsApiList: ["chooseWXPay", "sendTemplateMessage"], // 需要使用的JS接口列表 + }); + + wx.ready(function () { + // 在这里调用微信JS-SDK的接口 + wx.sendTemplateMessage({ + touser: openId, + template_id, + url, + miniprogram: { + appid, + pagepath, + }, + data: { + keyword1: { + value, + }, + }, + success: function (res) { + console.log('success', res) + }, + fail: function (error) { + console.error('error', error) + }, + }); + }); +};