Skip to content

Commit

Permalink
订阅功能最新测试通过,添加首页排序功能,优化缓存openid,优化订阅取消按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
jiajia.sun committed Dec 27, 2020
1 parent d637cc6 commit ac15613
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 128 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ yarn-error.log*
*.ntvs*
*.njsproj
*.sln
manifest.json
5 changes: 4 additions & 1 deletion App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
},
};
</script>
Expand Down
2 changes: 1 addition & 1 deletion cloudfunctions-aliyun/api/models/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}
Expand Down
92 changes: 51 additions & 41 deletions cloudfunctions-aliyun/send/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

};
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "外卖专享优惠",
"appid" : "",
"name" : "惠吃会喝",
"appid" : "__UNI__B7F4003",
"description" : "",
"versionName" : "1.0.0",
"versionCode" : "100",
Expand Down Expand Up @@ -42,7 +42,7 @@
},
"quickapp" : {},
"mp-weixin" : {
"appid" : "",
"appid" : "wx9472d5ad54e879ed",
"setting" : {
"urlCheck" : true,
"minified" : true
Expand Down
2 changes: 1 addition & 1 deletion pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}],
"globalStyle": {
"navigationBarTextStyle": "white",
"navigationBarTitleText": "外卖专享优惠",
"navigationBarTitleText": "惠吃会喝",
"navigationBarBackgroundColor": "#007AFF",
"backgroundColor": "#FFFFFF",
"titleView": false,
Expand Down
Loading

0 comments on commit ac15613

Please sign in to comment.