103 lines
3.2 KiB
TypeScript
103 lines
3.2 KiB
TypeScript
import cloud from '@lafjs/cloud'
|
||
import * as crypto from 'crypto';
|
||
const db = cloud.database();
|
||
const ThinkingData = require('thinkingdata-node');
|
||
export default async function (ctx: FunctionContext) {
|
||
let uid = ctx.body.uid;
|
||
let outTradeNo = ctx.body.outTradeNo;
|
||
let user = await db.collection("users").where({ _id: uid }).getOne();
|
||
if (user.data == null) {
|
||
return { code: 0, data: null, msg: "未获取到玩家数据" };
|
||
}
|
||
let res = await db.collection("order").where({ outTradeNo: outTradeNo }).getOne();
|
||
if (res.data.state == 1) {
|
||
return {
|
||
code: 1, data: {
|
||
pay_state: 2
|
||
}, msg: "成功"
|
||
};
|
||
} else if (res.data.state == 2) {
|
||
return {
|
||
code: 1, data: {
|
||
pay_state: 1,
|
||
}, msg: "已领取奖励"
|
||
}
|
||
} else {
|
||
return {
|
||
code: 0, data: {
|
||
pay_state: 1,
|
||
}, msg: "充值未成功"
|
||
}
|
||
};
|
||
}
|
||
const propName = {
|
||
"金币包1": "gold_1",
|
||
"金币包2": "gold_2",
|
||
"金币包3": "gold_3",
|
||
"金币包4": "gold_4",
|
||
"金币包5": "gold_5",
|
||
"金币包6": "gold_6",
|
||
"无限体力组合包1": "unlimited_health_bundle_1",
|
||
"无限体力组合包2": "unlimited_health_bundle_2",
|
||
"无限体力组合包3": "unlimited_health_bundle_3",
|
||
"局内购买冻结": "freeze_in_game",
|
||
"局内购买锤子": "hammer_in_game",
|
||
"局内购买魔棒": "wand_in_gamerefill",
|
||
"补满体力": "health",
|
||
"新手礼包": "starter_pack",
|
||
};
|
||
function hmacSha256(sessionKey, signData) {
|
||
const hmac = crypto.createHmac('sha256', sessionKey);
|
||
hmac.update(signData);
|
||
return hmac.digest('hex');
|
||
}
|
||
const getClientIp = (req) => {
|
||
return (
|
||
req.headers['x-forwarded-for']?.split(',')[0]?.trim() || // 代理链中的第一个 IP
|
||
req.headers['x-real-ip'] || // Nginx 配置的 real-ip
|
||
req.socket.remoteAddress // 原始 IP(可能是代理)
|
||
);
|
||
};
|
||
async function sead(order, userInfo, ip) {
|
||
console.error("上传数数");
|
||
//db.collection("susu").add({order: order,time: Date.now()});
|
||
if (!userInfo.distinctId) {
|
||
console.log("未找到distinctId无法上传数数")
|
||
return;
|
||
}
|
||
let id = '95993f9ab6f1402a87abe5147827e5e0';
|
||
if (userInfo.isDebug != "true") {
|
||
id = '40e3d5c5f2af49a4a074205564ce5dbb';
|
||
}
|
||
let teSDK = ThinkingData.initWithBatchMode(id, 'https://data.nika4fun.com/sync_data', {
|
||
dryRun: false, // report data to TE or not
|
||
deviceId: "123456789",//设备唯一标识
|
||
});
|
||
let trackEvent = {
|
||
accountId: order.openid,
|
||
distinctId: userInfo.distinctId,//访客id
|
||
event: 'payment',
|
||
time: new Date(Date.now() + 8 * 3600000),
|
||
ip: ip,
|
||
properties: {
|
||
order_id: order.outTradeNo,
|
||
pay_amount: order.goodsPrice,
|
||
payment_name: order.itemid,
|
||
payment_num: order.itemCount,
|
||
payment_type: "Android",
|
||
is_on_table: Number(userInfo.addLevel) >= 5,
|
||
current_level: userInfo.levelAmount, //当前关卡等级 number
|
||
current_health: userInfo.healthAmount, //当前体力值
|
||
tmp_coin: userInfo.coinAmount,//当前金币
|
||
version: "1.6",
|
||
user_id: userInfo._id, //用户id
|
||
pay_user: userInfo.pay_user,
|
||
register_time: userInfo.register_time
|
||
},
|
||
callback(e) { if (e) { } }
|
||
};
|
||
teSDK.track(trackEvent);
|
||
teSDK.close();
|
||
return;
|
||
}
|