Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update messsend #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"pages": [
"pages/index/index",
"pages/user/index",
"pages/messsend/index",
"pages/reserve/index",
"pages/reserve-detail/index",
"pages/wxaqrcode/index",
Expand Down
6 changes: 5 additions & 1 deletion client/pages/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ Page({
id: "wxaqrcode",
name: "小程序码"
},
{
id: "messsend",
name: "订阅消息"
},
{
id: "reserve",
name: "模板消息"
name: "服务消息"
},
{
id: "customer-msg",
Expand Down
65 changes: 65 additions & 0 deletions client/pages/messsend/index.js
Original file line number Diff line number Diff line change
@@ -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;
}
});
4 changes: 4 additions & 0 deletions client/pages/messsend/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<view class="container" style="min-height:auto">
<textarea class="textinput" bindinput="textin"></textarea>
<button class="submitbtn" bindtap="onSubscribe">发送订阅消息</button>
</view>
18 changes: 18 additions & 0 deletions client/pages/messsend/index.wxss
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 7 additions & 0 deletions cloud/functions/send/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"permissions": {
"openapi": [
"subscribeMessage.send"
]
}
}
16 changes: 16 additions & 0 deletions cloud/functions/send/index.js
Original file line number Diff line number Diff line change
@@ -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;
}
};
14 changes: 14 additions & 0 deletions cloud/functions/send/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}