From ac15613d825e8f1280332116f9d65eb57f1d8a7f Mon Sep 17 00:00:00 2001 From: "jiajia.sun" Date: Sun, 27 Dec 2020 23:35:57 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E8=AE=A2=E9=98=85=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E6=B5=8B=E8=AF=95=E9=80=9A=E8=BF=87=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A6=96=E9=A1=B5=E6=8E=92=E5=BA=8F=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E4=BC=98=E5=8C=96=E7=BC=93=E5=AD=98openid?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E8=AE=A2=E9=98=85=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + App.vue | 5 +- cloudfunctions-aliyun/api/models/home.js | 2 +- cloudfunctions-aliyun/send/index.js | 92 +++++---- manifest.json | 6 +- pages.json | 2 +- pages/index/index.vue | 249 +++++++++++++++-------- static/error.png | Bin 0 -> 9196 bytes 8 files changed, 229 insertions(+), 128 deletions(-) create mode 100644 static/error.png diff --git a/.gitignore b/.gitignore index 4a3296c..f31b6e4 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ yarn-error.log* *.ntvs* *.njsproj *.sln +manifest.json \ No newline at end of file diff --git a/App.vue b/App.vue index 2c467e2..a446578 100644 --- a/App.vue +++ b/App.vue @@ -15,7 +15,10 @@ export default { openid: 'https://88d58ce0-c72d-4ad5-9ad5-5196f032ef71.bspapp.com/http/api/openid', }, subscribe: 'https://88d58ce0-c72d-4ad5-9ad5-5196f032ef71.bspapp.com/http/subscribe', - } + openid: '', + }, + + }; diff --git a/cloudfunctions-aliyun/api/models/home.js b/cloudfunctions-aliyun/api/models/home.js index 4736505..b3c7dd9 100644 --- a/cloudfunctions-aliyun/api/models/home.js +++ b/cloudfunctions-aliyun/api/models/home.js @@ -6,7 +6,7 @@ var home = { return tabs }, coupons: () => { - let coupons = db.collection('coupon').get(); + let coupons = db.collection('coupon').orderBy("sort", "desc").get(); return coupons }, } diff --git a/cloudfunctions-aliyun/send/index.js b/cloudfunctions-aliyun/send/index.js index e4991dd..c1d7aae 100644 --- a/cloudfunctions-aliyun/send/index.js +++ b/cloudfunctions-aliyun/send/index.js @@ -35,55 +35,65 @@ exports.main = async (event, context) => { // 从云开发数据库中查询等待发送的消息列表 const messages = await db .collection('messages') - // 查询条件这里做了简化,只查找了状态为未发送的消息 - // 在真正的生产环境,可以根据开课日期等条件筛选应该发送哪些消息 .where({ send: false, }) .get(); const now_date = getFormatDate(0); + let sendArr = []; // 循环消息列表 const sendPromises = messages.data.map(async message => { // 发送订阅消息 - const sendUrl = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=' + access_token; - let send_data = { - touser: message.touser, - page: "pages/index/index", - data: { - thing1: { - value: "记得领红包哦!", + try{ + if (sendArr.includes(message.touser)){ + console.log('该用户已发送!') + }else + { + sendArr.push(message.touser); + const sendUrl = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=' + access_token; + let send_data = { + touser: message.touser, + page: "pages/index/index", + data: { + thing1: { + value: "记得领红包哦!", + }, + thing4: { + value: message.data, + }, + thing5: { + value: now_date, + } }, - thing4: { - value: message.data, - }, - thing5: { - value: now_date, - } - }, - template_id: message.templateId, - }; - console.log(send_data); - // uniCloud.httpclient 发起请求 - const sendres = await uniCloud.httpclient.request(sendUrl, - { - data: send_data, - method: 'POST', - contentType: 'json', - dataType:"json", - }, - function(error, response, body) { - if (!error && response.statusCode == 200) { - console.log(response) // 请求成功的处理逻辑 - // 发送成功后将消息的状态改为已发送 - db.collection('messages') - .doc(message._id) - .update({ - data: { - send: true, - }, - }); - } + template_id: message.templateId, + }; + console.log(send_data); + + // uniCloud.httpclient 发起请求 + const sendres = await uniCloud.httpclient.request(sendUrl, + { + data: send_data, + method: 'POST', + contentType: 'json', + dataType:"json", + }); + console.log('发送成功'); + console.log(message); + // 发送成功后将消息的状态改为已发送 + return await db.collection('messages') + .doc(message._id) + .update({ + send: true, + sendDate: now_date, + } + ) + } + }catch(e){ + //TODO handle the exception + console.log('发送失败'); + console.log(message); } - ); -}) + }); + return Promise.all(sendPromises) + }; \ No newline at end of file diff --git a/manifest.json b/manifest.json index 4714a6c..c56a36c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { - "name" : "外卖专享优惠", - "appid" : "", + "name" : "惠吃会喝", + "appid" : "__UNI__B7F4003", "description" : "", "versionName" : "1.0.0", "versionCode" : "100", @@ -42,7 +42,7 @@ }, "quickapp" : {}, "mp-weixin" : { - "appid" : "", + "appid" : "wx9472d5ad54e879ed", "setting" : { "urlCheck" : true, "minified" : true diff --git a/pages.json b/pages.json index d3e374a..01f38c3 100644 --- a/pages.json +++ b/pages.json @@ -4,7 +4,7 @@ }], "globalStyle": { "navigationBarTextStyle": "white", - "navigationBarTitleText": "外卖专享优惠", + "navigationBarTitleText": "惠吃会喝", "navigationBarBackgroundColor": "#007AFF", "backgroundColor": "#FFFFFF", "titleView": false, diff --git a/pages/index/index.vue b/pages/index/index.vue index 99f4f60..fd15a97 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -21,6 +21,8 @@