From 5cca2d8181d23bfc672eea44c03d20cc867bb9af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=86=A0=E5=AE=87hp?= <2786054116@qq.com> Date: Wed, 8 Apr 2020 13:03:34 +0800 Subject: [PATCH] update messsend --- client/app.json | 1 + client/pages/index/index.js | 6 ++- client/pages/messsend/index.js | 65 +++++++++++++++++++++++++++++++ client/pages/messsend/index.wxml | 4 ++ client/pages/messsend/index.wxss | 18 +++++++++ cloud/functions/send/config.json | 7 ++++ cloud/functions/send/index.js | 16 ++++++++ cloud/functions/send/package.json | 14 +++++++ 8 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 client/pages/messsend/index.js create mode 100644 client/pages/messsend/index.wxml create mode 100644 client/pages/messsend/index.wxss create mode 100644 cloud/functions/send/config.json create mode 100644 cloud/functions/send/index.js create mode 100644 cloud/functions/send/package.json diff --git a/client/app.json b/client/app.json index f50e9f6..ad86289 100755 --- a/client/app.json +++ b/client/app.json @@ -2,6 +2,7 @@ "pages": [ "pages/index/index", "pages/user/index", + "pages/messsend/index", "pages/reserve/index", "pages/reserve-detail/index", "pages/wxaqrcode/index", diff --git a/client/pages/index/index.js b/client/pages/index/index.js index 6550ebd..79f8181 100755 --- a/client/pages/index/index.js +++ b/client/pages/index/index.js @@ -12,9 +12,13 @@ Page({ id: "wxaqrcode", name: "小程序码" }, + { + id: "messsend", + name: "订阅消息" + }, { id: "reserve", - name: "模板消息" + name: "服务消息" }, { id: "customer-msg", diff --git a/client/pages/messsend/index.js b/client/pages/messsend/index.js new file mode 100644 index 0000000..0a4f444 --- /dev/null +++ b/client/pages/messsend/index.js @@ -0,0 +1,65 @@ +const app = getApp(); +const lessonTmplId = ''; + +Page({ + onSubscribe: function(e) { + if(!this.text||this.text==''){ + wx.showToast({ + title: '没有填写内容', + icon:'none' + }) + return; + } + let date = new Date(); + const item = { + thing2: { + value: this.text + }, + time4: { + value: this.formdate(date) + } + } + console.log(item); + wx.requestSubscribeMessage({ + tmplIds: [lessonTmplId], + success(res) { + if (res.errMsg === 'requestSubscribeMessage:ok') { + wx.showLoading({ + title: '订阅中', + mask:true + }); + wx.cloud.callFunction({ + name: 'send', + data: { + data: item, + date: date, + templateId: lessonTmplId, + }, + }).then(() => { + wx.hideLoading(); + wx.showToast({ + title: '订阅成功' + }); + }).catch(() => { + wx.showToast({ + title: '订阅失败', + icon: 'none' + }); + }); + } + }, + }); + }, + textin(e){ + this.text = e.detail.value; + }, + formdate(date){ + var year = date.getFullYear(); + var month = date.getMonth() + 1; + var date1 = date.getDate(); + var hour = date.getHours(); + var minutes = date.getMinutes(); + var second = date.getSeconds(); + return year + "年" + month + "月" + date1 + "日 " + hour + ":" + minutes; + } +}); \ No newline at end of file diff --git a/client/pages/messsend/index.wxml b/client/pages/messsend/index.wxml new file mode 100644 index 0000000..8e367cc --- /dev/null +++ b/client/pages/messsend/index.wxml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/client/pages/messsend/index.wxss b/client/pages/messsend/index.wxss new file mode 100644 index 0000000..43fcd0b --- /dev/null +++ b/client/pages/messsend/index.wxss @@ -0,0 +1,18 @@ +Page{ + background-color:#f2f2f2; +} +.textinput{ + background-color: white; + width: 650rpx; + margin: 40rpx; + padding: 10rpx; + line-height: 1.5; + font-weight: 400; + font-size: 17px; +} +.submitbtn{ + background-color: #286dee; + color: white; + min-width: 650rpx; + font-weight: 400; +} \ No newline at end of file diff --git a/cloud/functions/send/config.json b/cloud/functions/send/config.json new file mode 100644 index 0000000..310b4f8 --- /dev/null +++ b/cloud/functions/send/config.json @@ -0,0 +1,7 @@ +{ + "permissions": { + "openapi": [ + "subscribeMessage.send" + ] + } +} \ No newline at end of file diff --git a/cloud/functions/send/index.js b/cloud/functions/send/index.js new file mode 100644 index 0000000..7380d1c --- /dev/null +++ b/cloud/functions/send/index.js @@ -0,0 +1,16 @@ +const cloud = require('wx-server-sdk'); +cloud.init(); + +exports.main = async (event, context) => { + try { + await cloud.openapi.subscribeMessage.send({ + touser: event.userInfo.openId, + page: 'pages/messsend/index', + data: event.data, + templateId: event.templateId + }); + } catch (err) { + console.log(err); + return err; + } +}; \ No newline at end of file diff --git a/cloud/functions/send/package.json b/cloud/functions/send/package.json new file mode 100644 index 0000000..30af06f --- /dev/null +++ b/cloud/functions/send/package.json @@ -0,0 +1,14 @@ +{ + "name": "send", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "wx-server-sdk": "~1.8.2" + } +} \ No newline at end of file