Skip to content

Commit

Permalink
feat:send-template-message
Browse files Browse the repository at this point in the history
  • Loading branch information
wybieshang committed Mar 25, 2024
1 parent 0b902b0 commit a6f1ba3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/cw/wechat_sdk_share/logics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: sendTemplateMessage
description: 发送模版消息
type: both
belong: logic
labels: [Runtime]
41 changes: 41 additions & 0 deletions packages/cw/wechat_sdk_share/logics/sendTemplateMessage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @param {string} options <false> 这是一个描述
* @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)
},
});
});
};

0 comments on commit a6f1ba3

Please sign in to comment.