unicloud云函数抖音小程序订单推送示例

'use strict';
const appid = ''
const secret = ''
const Commodity_figure =""//商品图链接
exports.main = async (event, context) => {

//获取token
	const URL1 = `https://developer.toutiao.com/api/apps/v2/token`

	let res_ = await uniCloud.httpclient.request(URL1, {
		method: 'POST',
		dataType: 'json',
		contentType: 'json', // 指定以application/json发送data内的数据
		headers: {
			"Content-Type": "application/json"
		},
		data: {
			"appid": appid,
			"secret": secret,
			"grant_type": "client_credential"
		},

	})


	const URL = `https://developer.toutiao.com/api/apps/order/v2/push`

	let res_1 = await uniCloud.httpclient.request(URL, {
		method: 'POST',
		dataType: 'json',
		contentType: 'json', // 指定以application/json发送data内的数据
		headers: {
			"Content-Type": "application/json"
		},
		data: {
			"access_token": res_.data.data.access_token, // string类型,必传字段
			"app_name": "douyin",
			"open_id": event.open_id, // 小程序open id
			"update_time": Number(new Date()), // 订单信息变更时间,13位毫秒级时间戳
			"order_type": 0, // 订单类型
			"order_status": event.order_status, //当order_type为0(普通小程序订单,非poi订单)时,请关注,必传
			"order_detail": JSON.stringify({
				"order_id": event.order_id, //开发者侧业务单号
				"create_time": Number(new Date()), //订单创建的时间
				"status": event.pay_status, //订单状态,待支付\已支付\已取消\已超时\已核销\退款中\已退款\退款失败
				"amount": 1, //订单商品总数
				"total_price": event.itemdata.total_amount, //订单金额
				"detail_url": "page/user/user", //跳转小程序路径
				"item_list": [{//商品数据
					"item_code": event.order_id,
					"img": Commodity_figure,
					"title": event.itemdata.subject,
					"sub_title": event.itemdata.body_,
					"amount": 1,
					"price": event.itemdata.total_amount,

				}]
			})

		}

	})


	//返回数据给客户端
	return res_1
};


写小程序订单推送时被抖音开发者文档里的数据结构卡了一会,把代码贴出来希望能帮到遇到这个问题的朋友

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值