xc-app/uniCloud-aliyun/cloudfunctions/public/index.js

26 lines
853 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
switch (event.action) {
case 'getUrlScheme': {
return getUrlScheme(event.options)//与官方文档区别:小程序页面接受的参数
}
}
return 'action not found'
}
async function getUrlScheme(options) {
//return options;
return cloud.openapi.urlscheme.generate({
jumpWxa: {
path: '/pages/pay/pay', // 调转到小程序要打开的页面路径,根据实际业务设置
query: options,//与官方文档区别:小程序页面接受的参数
},
// 如果想不过期则置为 false并可以存到数据库
isExpire: false,
// 一分钟有效期
expireTime: parseInt(Date.now() / 1000 + 60),
})
}