From 0808489f16ec62f5cc1e08fd65cae463b4dac06b Mon Sep 17 00:00:00 2001 From: huanghaipeng Date: Wed, 2 Sep 2026 17:34:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=B5=8B=E8=AF=95=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- laf-cloud/functions/TokenMgr.ts | 6 +- laf-cloud/functions/abConfigAdmin.ts | 2 +- laf-cloud/functions/clearSrank.ts | 4 +- laf-cloud/functions/creatCDkTwo.ts | 44 +++------- laf-cloud/functions/drawHead.ts | 2 +- laf-cloud/functions/getRank.ts | 2 +- laf-cloud/functions/getSRank.ts | 12 ++- laf-cloud/functions/getTaskReward.ts | 82 ++++--------------- laf-cloud/functions/getUserInfoByID.ts | 8 +- laf-cloud/functions/jungleConfig.ts | 6 ++ laf-cloud/functions/limitedTimeEvent.ts | 8 +- laf-cloud/functions/login.ts | 26 +++--- laf-cloud/functions/monthGetReward.ts | 8 +- laf-cloud/functions/passCheck.ts | 8 +- laf-cloud/functions/passCheckLv.ts | 8 +- laf-cloud/functions/rebornGift.ts | 8 +- .../functions/searchPlayerDataByLevel.ts | 76 ++++++++--------- laf-cloud/functions/setForcedUpdate.ts | 8 +- laf-cloud/functions/setHeadArr.ts | 8 +- laf-cloud/functions/setUserLevel.ts | 8 +- laf-cloud/functions/setWinStreak.ts | 8 +- laf-cloud/functions/shareLvSuccess.ts | 8 +- laf-cloud/functions/shopDouble.ts | 8 +- laf-cloud/functions/test.ts | 8 +- laf-cloud/functions/userData.ts | 8 +- laf-cloud/functions/userHealth.ts | 8 +- laf-cloud/functions/userLevel.ts | 12 +-- laf-cloud/functions/userPower.ts | 8 +- laf-cloud/functions/userProp.ts | 8 +- laf-cloud/functions/wx/KeFuInfo.ts | 14 ++-- laf-cloud/functions/wx/iosgetPayInfo.ts | 10 +-- laf-cloud/functions/wx/iosorderPaySig.ts | 2 +- laf-cloud/functions/wx/orderPaySig.ts | 2 +- laf-cloud/functions/wx/payCallBack.ts | 5 +- 34 files changed, 190 insertions(+), 253 deletions(-) diff --git a/laf-cloud/functions/TokenMgr.ts b/laf-cloud/functions/TokenMgr.ts index ee6e113..3d47faa 100644 --- a/laf-cloud/functions/TokenMgr.ts +++ b/laf-cloud/functions/TokenMgr.ts @@ -1,7 +1,7 @@ import cloud from '@lafjs/cloud'; import * as crypto from 'crypto'; const appid = 'wx30f74367b3d3e7a6'; // 微信小程序 AppId -const appsecret = 'a3417fe674feadb77809d8f9a365190d'; // 微信小程序 AppSecret +const appsecret = process.env.WX_MINIGAME_APP_SECRET; // 微信小程序 AppSecret //定时获取Token export default async function (ctx: FunctionContext) { @@ -44,10 +44,10 @@ async function getWxToken1() { } async function PostToken(wxToken) { - const token = `rR0KncGAzwyjSjaxCcJvtkbfVhkszLiI`; + const token = process.env.GRAVITY_ACCESS_TOKEN; const url = `https://backend.gravity-engine.com/event_center/api/v1/base/wx/access_token/refresh/?access_token=${token}`; const time = Math.floor(Date.now() / 1000); - const appkey = `1RU5blZdYzulktjApFONuwgQJx7erwzDfdPoig0yM9opSbIq32BTH4Kvj6hfcmir`; + const appkey = process.env.GRAVITY_APP_KEY; const str: string = `app_key=${appkey}&wx_access_token=${wxToken}¤t_time=${time}`; const sign: string = crypto.createHash('md5').update(str).digest('hex').toLowerCase(); const data = { diff --git a/laf-cloud/functions/abConfigAdmin.ts b/laf-cloud/functions/abConfigAdmin.ts index 50414ab..6edd1e5 100644 --- a/laf-cloud/functions/abConfigAdmin.ts +++ b/laf-cloud/functions/abConfigAdmin.ts @@ -2,7 +2,7 @@ import cloud from '@lafjs/cloud' const db = cloud.database(); const COLLECTION = "ab_config"; -const DEFAULT_ADMIN_TOKEN = "abtest-admin-token"; +const DEFAULT_ADMIN_TOKEN = process.env.AB_ADMIN_TOKEN; export default async function (ctx: FunctionContext) { const action = ctx.body?.action || ctx.query?.action || "list"; diff --git a/laf-cloud/functions/clearSrank.ts b/laf-cloud/functions/clearSrank.ts index 75eb27c..12f3616 100644 --- a/laf-cloud/functions/clearSrank.ts +++ b/laf-cloud/functions/clearSrank.ts @@ -1,10 +1,10 @@ import cloud from '@lafjs/cloud' const db = cloud.database(); export default async function (ctx: FunctionContext) { - await db.collection("sRank").where({ _id: "69fabd35b4d89b170da4bf5e" }).update({ total: null }); + await db.collection("sRank").where({ _id: process.env.SRANK_ID }).update({ total: null }); await db.collection("users").update({ levelTJ: 0, addLevel: 0 }, { multi: true }); await db.collection("usersAd").update({ levelTJ: 0, addLevel: 0 }, { multi: true }); - await db.collection("sRank").where({ _id: "69fabd35b4d89b170da4bf5e" }).update({ total: null }); + await db.collection("sRank").where({ _id: process.env.SRANK_ID }).update({ total: null }); cloud.shared.set("iosOrder", {}); return { data: 'hi, laf' } } diff --git a/laf-cloud/functions/creatCDkTwo.ts b/laf-cloud/functions/creatCDkTwo.ts index 6113142..2ffded0 100644 --- a/laf-cloud/functions/creatCDkTwo.ts +++ b/laf-cloud/functions/creatCDkTwo.ts @@ -1,37 +1,15 @@ import cloud from '@lafjs/cloud' const db = cloud.database(); +import Utils from "@/Utils"; export default async function (ctx: FunctionContext) { - let code = ctx.body.code; - if (!code) { - return { data: "code无效" }; + let cdk = ctx.body.cdk; + cdk = cdk.toLowerCase(); + let info = await db.collection("idcount").where({ _id: process.env.IDCOUNT_NAME }).getOne(); + let count = info.data.count; + if (count.includes(cdk)) { + return { code: 0, data: "兑换码已存在" }; } - let type = ctx.body.type; - let res = await db.collection("cdk").where({ code: code }).getOne(); - if (type == 1) { - if (res.data && res.data.code == code) { - return { data: "兑换码" + code + "已存在" }; - } - let ret = await db.collection("cdk").add({ - code: code, - creatTime: new Date(Date.now() + 8 * 3600000), - start: ctx.body.start_time, - end_time: ctx.body.end_time, - }) - if (ret.id) { - return { data: "兑换码" + code + "保存成功" }; - } else { - return { data: "兑换码" + code + "保存失败" }; - } - - } else if (type == 2) { - if (!res.data) { - return { data: "兑换码不存在" }; - } - let ret1 = await db.collection("cdk").where({ code: code }).remove({ multi: true }); - if (ret1.ok) { - return { data: "兑换码" + code + "删除成功" }; - } else { - return { data: "兑换码" + code + "删除失败" }; - } - } -} \ No newline at end of file + count.push(cdk); + await db.collection("idcount").where({ _id: process.env.IDCOUNT_NAME }).update({ count: count }); + return { code: 1, data: "兑换码保存成功" }; +} diff --git a/laf-cloud/functions/drawHead.ts b/laf-cloud/functions/drawHead.ts index 2f77f57..0a8943c 100644 --- a/laf-cloud/functions/drawHead.ts +++ b/laf-cloud/functions/drawHead.ts @@ -32,7 +32,7 @@ export default async function (ctx: FunctionContext) { let headArr = res.data.headArr; if (!headArr) { - headArr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]; ]; + headArr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] ]; } diff --git a/laf-cloud/functions/getRank.ts b/laf-cloud/functions/getRank.ts index 2a91d00..7b8a1cc 100644 --- a/laf-cloud/functions/getRank.ts +++ b/laf-cloud/functions/getRank.ts @@ -8,7 +8,7 @@ export default async function (ctx: FunctionContext) { if (gameName == "iaa") { res1 = await db.collection("rank").where({ _id: "" }).getOne(); } else { - res1 = await db.collection("rank").where({ _id: "69fac0d98463a95668c5e5d9" }).getOne(); + res1 = await db.collection("rank").where({ _id: process.env.RANK_ID }).getOne(); } let rank = JSON.parse(res1.data.rank) let list = []; diff --git a/laf-cloud/functions/getSRank.ts b/laf-cloud/functions/getSRank.ts index 03b6884..fd6c8d5 100644 --- a/laf-cloud/functions/getSRank.ts +++ b/laf-cloud/functions/getSRank.ts @@ -2,13 +2,11 @@ import cloud from '@lafjs/cloud' const db = cloud.database(); import Utils from "@/Utils"; export default async function (ctx: FunctionContext) { - const uid = ctx.body.uid; - let db1 = "69fabd35b4d89b170da4bf5e"; - const gameName = ctx.body.gameName; - if (gameName == "iaa") { - db1 = "69fabd418463a95668c5e5d3"; - } - let rankInfo = await db.collection("sRank").where({ _id: db1 }).getOne(); + // const gameName = ctx.body.gameName; + // if (gameName == "iaa") { + // db1 = "69fabd418463a95668c5e5d3"; + // } + let rankInfo = await db.collection("sRank").where({ _id: process.env.SRANK_id }).getOne(); //console.log(rankInfo); return { code: 1, data: rankInfo.data.total, msg: "成功" }; } diff --git a/laf-cloud/functions/getTaskReward.ts b/laf-cloud/functions/getTaskReward.ts index b4978b2..69fd76c 100644 --- a/laf-cloud/functions/getTaskReward.ts +++ b/laf-cloud/functions/getTaskReward.ts @@ -1,80 +1,30 @@ import cloud from '@lafjs/cloud' const db = cloud.database(); import Utils from "@/Utils"; -const taskTarget = { - levelPass: 3, - share: 1, - useEnergy: 10, - useProp: 3, -} export default async function (ctx: FunctionContext) { const uid = ctx.body.uid; - const taskType = JSON.parse(ctx.body.taskType); if (!uid) { return { code: 0, data: null, msg: "未获取到uid" }; } - if (!taskType) { - return { code: 0, data: null, msg: "未获取到taskType" } - } let dbname = "users"; - const gameName = ctx.body.gameName; - if (gameName == "iaa") { - dbname = "usersAd"; - } + // const gameName = ctx.body.gameName; + // if (gameName == "iaa") { + // dbname = "usersAd"; + // } let res = await db.collection(dbname).where({ _id: uid }).getOne(); - if (res.data == null) { - return { code: 0, data: null, msg: "未获取到用户信息" }; - } - const token1 = ctx.body.token; - if (res.data && res.data.token) { - let istoken = Utils.checkToken(token1, res.data.token); - if (!istoken) { - return { code: 0, data: null, msg: "token校验失败" }; + if (!res.data) { + return { + code: 0, data: { id: null, name: null, useravatar: null, useravatarIcon: null }, msg: "未获取到玩家信息" } } - let task = res.data.task; - if (task) { - task = JSON.parse(task); - } else { - task = { - levelPass: { - value: 0, - state: 0, - }, - share: { - value: 0, - state: 0, - }, - useEnergy: { - value: 0, - state: 0, - }, - useProp: { - value: 0, - state: 0, - } - } + return { + code: 1, + data: { + id: res.data._id, + name: res.data.username, + useravatar: res.data.useravatar, + useravatarIcon: res.data.useravatarIcon + }, + msg: "成功" } - for (var key in task) { - task[key].target = taskTarget[key]; - } - for (let i = 0; i < taskType.length; i++) { - if (!task[taskType[i]]) { - return { code: 0, data: null, msg: "请输入正确task类型" }; - } - if (task[taskType[i]].value < task[taskType[i]].target) { - return { code: 0, data: null, msg: "请先完成任务" }; - } - if (task[taskType[i]].state == 2) { - return { code: 0, data: null, msg: "不能重复领取奖励" }; - } - task[taskType[i]].state = 2; - } - - let data = { - task: task, - taskTime: Date.now() + 8 * 3600000 - } - await db.collection(dbname).where({ _id: uid }).update({ task: JSON.stringify(task), taskTime: Date.now() + 8 * 3600000 }); - return { code: 1, data: data, msg: "领取成功" }; } diff --git a/laf-cloud/functions/getUserInfoByID.ts b/laf-cloud/functions/getUserInfoByID.ts index d4ab1e9..69fd76c 100644 --- a/laf-cloud/functions/getUserInfoByID.ts +++ b/laf-cloud/functions/getUserInfoByID.ts @@ -7,10 +7,10 @@ export default async function (ctx: FunctionContext) { return { code: 0, data: null, msg: "未获取到uid" }; } let dbname = "users"; - const gameName = ctx.body.gameName; - if (gameName == "iaa") { - dbname = "usersAd"; - } + // const gameName = ctx.body.gameName; + // if (gameName == "iaa") { + // dbname = "usersAd"; + // } let res = await db.collection(dbname).where({ _id: uid }).getOne(); if (!res.data) { return { diff --git a/laf-cloud/functions/jungleConfig.ts b/laf-cloud/functions/jungleConfig.ts index b6491da..332eca8 100644 --- a/laf-cloud/functions/jungleConfig.ts +++ b/laf-cloud/functions/jungleConfig.ts @@ -1,3 +1,9 @@ +import cloud from '@lafjs/cloud' + +export default async function (ctx: FunctionContext) { + console.log('Hello World') + return { data: 'hi, laf' } +} export type JungleRewardType = "coin" | "freeze" | "hammer" | "magic_wand" | "infinite_health"; export interface JungleRewardConfig { diff --git a/laf-cloud/functions/limitedTimeEvent.ts b/laf-cloud/functions/limitedTimeEvent.ts index 7c170b1..0eb6749 100644 --- a/laf-cloud/functions/limitedTimeEvent.ts +++ b/laf-cloud/functions/limitedTimeEvent.ts @@ -6,10 +6,10 @@ export default async function (ctx: FunctionContext) { const uid = ctx.body.uid; const event = ctx.body.event; let dbname = "users"; - const gameName = ctx.body.gameName; - if (gameName == "iaa") { - dbname = "usersAd"; - } + // const gameName = ctx.body.gameName; + // if (gameName == "iaa") { + // dbname = "usersAd"; + // } if (!action) { return { code: 0, data: null, msg: "未获取到action" }; } diff --git a/laf-cloud/functions/login.ts b/laf-cloud/functions/login.ts index a86f441..d9bd48b 100644 --- a/laf-cloud/functions/login.ts +++ b/laf-cloud/functions/login.ts @@ -14,8 +14,8 @@ import { const JungleConfig: any = JungleConfigModule as any; const db = cloud.database(); import crypto from 'crypto'; -const mchid = "1719895437";//商户id -const serialNo = "2A97ED6ED441E55600EBC8830B9EC889ED41496E";//证书序列号 +const mchid = process.env.WX_MCH_ID;//商户id +const serialNo = process.env.WX_MCH_CERT_SERIAL_NO;//证书序列号 const ThinkingData = require('thinkingdata-node'); import Ip2region from 'ip2region'; const query = new Ip2region(); @@ -32,20 +32,20 @@ export default async function (ctx: FunctionContext) { const from = body.from; const supportsWucaiMigration = Number(body.wucai_capability) >= 1; let dbname = "users"; - const gameName = body.gameName; - if (gameName == "iaa") { - dbname = "usersAd"; - } + // const gameName = body.gameName; + // if (gameName == "iaa") { + // dbname = "usersAd"; + // } if (from === "wucai" && dbname !== "users") { return wucaiLoginFail("WUCAI_UNSUPPORTED_GAME", "五彩账号迁移仅支持主用户库"); } if (from === "wucai" && !supportsWucaiMigration) { return wucaiLoginFail("WUCAI_CLIENT_UPGRADE_REQUIRED", "当前客户端不支持五彩账号迁移,请更新游戏"); } - let idname = "69faba99b4d89b170da4bf56"; - if (gameName == "iaa") { - idname = "69fabaacb4d89b170da4bf57"; - } + let idname = process.env.IDCOUNT_NAME; + // if (gameName == "iaa") { + // idname = "69fabaacb4d89b170da4bf57"; + // } let info = await getWXOpenId(code, dbname); if (!info) { return; @@ -359,7 +359,7 @@ const propName = { async function getWXOpenId(code, dbname) { let appid = "wx30f74367b3d3e7a6"; - let appsecret = "a3417fe674feadb77809d8f9a365190d"; + let appsecret = process.env.WX_MINIGAME_APP_SECRET; if (dbname == "usersAd") { appid = ""; appsecret = ""; @@ -516,7 +516,7 @@ function getABTestGroupValue(abTests: any, layerKey: string) { /**获取订单*/ async function getOrder(outTradeNo) { - const url = `https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/${outTradeNo}?mchid=1719895437`; + const url = `https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/${outTradeNo}?mchid=${mchid}`; const nonceStr = crypto.randomBytes(16).toString('hex'); const timestamp = Math.floor(Date.now() / 1000).toString(); let au = await sign(outTradeNo, nonceStr, timestamp); @@ -532,7 +532,7 @@ async function getOrder(outTradeNo) { return data; } async function sign(outTradeNo, nonceStr, timestamp) { - const data = `GET\n/v3/pay/transactions/out-trade-no/${outTradeNo}?mchid=1719895437\n${timestamp}\n${nonceStr}\n\n` + const data = `GET\n/v3/pay/transactions/out-trade-no/${outTradeNo}?mchid=${mchid}\n${timestamp}\n${nonceStr}\n\n` // 创建签名对象 const sign = crypto.createSign('RSA-SHA256'); // 更新签名内容 diff --git a/laf-cloud/functions/monthGetReward.ts b/laf-cloud/functions/monthGetReward.ts index 3f7089d..f366553 100644 --- a/laf-cloud/functions/monthGetReward.ts +++ b/laf-cloud/functions/monthGetReward.ts @@ -4,10 +4,10 @@ import Utils from "@/Utils"; export default async function (ctx: FunctionContext) { const uid = ctx.body.uid; let dbname = "users"; - const gameName = ctx.body.gameName; - if (gameName == "iaa") { - dbname = "usersAd"; - } + // const gameName = ctx.body.gameName; + // if (gameName == "iaa") { + // dbname = "usersAd"; + // } let res = await db.collection(dbname).where({ _id: uid }).getOne(); const token1 = ctx.body.token; if (res.data && res.data.token) { diff --git a/laf-cloud/functions/passCheck.ts b/laf-cloud/functions/passCheck.ts index f710714..13957f8 100644 --- a/laf-cloud/functions/passCheck.ts +++ b/laf-cloud/functions/passCheck.ts @@ -11,10 +11,10 @@ export default async function (ctx: FunctionContext) { return { code: 0, data: null, msg: "未获取到uid" }; } let dbname = "users"; - const gameName = ctx.body.gameName; - if (gameName == "iaa") { - dbname = "usersAd"; - } + // const gameName = ctx.body.gameName; + // if (gameName == "iaa") { + // dbname = "usersAd"; + // } let res = await db.collection(dbname).where({ _id: uid }).getOne(); const token1 = ctx.body.token; if (res.data && res.data.token) { diff --git a/laf-cloud/functions/passCheckLv.ts b/laf-cloud/functions/passCheckLv.ts index 69266c0..30beae6 100644 --- a/laf-cloud/functions/passCheckLv.ts +++ b/laf-cloud/functions/passCheckLv.ts @@ -11,10 +11,10 @@ export default async function (ctx: FunctionContext) { return { code: 0, data: null, msg: "未获取到uid" }; } let dbname = "users"; - const gameName = ctx.body.gameName; - if (gameName == "iaa") { - dbname = "usersAd"; - } + // const gameName = ctx.body.gameName; + // if (gameName == "iaa") { + // dbname = "usersAd"; + // } let res = await db.collection(dbname).where({ _id: uid }).getOne(); const token1 = ctx.body.token; if (res.data && res.data.token) { diff --git a/laf-cloud/functions/rebornGift.ts b/laf-cloud/functions/rebornGift.ts index f08c16a..ede46f9 100644 --- a/laf-cloud/functions/rebornGift.ts +++ b/laf-cloud/functions/rebornGift.ts @@ -7,10 +7,10 @@ export default async function (ctx: FunctionContext) { return { code: 0, data: null, msg: "参数错误" }; } let dbname = "users"; - const gameName = ctx.body.gameName; - if (gameName == "iaa") { - dbname = "usersAd"; - } + // const gameName = ctx.body.gameName; + // if (gameName == "iaa") { + // dbname = "usersAd"; + // } let res = await db.collection(dbname).where({ _id: uid }).getOne(); if (res.data == null) { return { code: 0, data: null, msg: "未获取到玩家数据" }; diff --git a/laf-cloud/functions/searchPlayerDataByLevel.ts b/laf-cloud/functions/searchPlayerDataByLevel.ts index 58bd00f..17e7ba7 100644 --- a/laf-cloud/functions/searchPlayerDataByLevel.ts +++ b/laf-cloud/functions/searchPlayerDataByLevel.ts @@ -3,49 +3,49 @@ const { MongoClient } = require('mongodb'); const db1 = cloud.database(); /**查询备份数据库 */ export default async function (ctx: FunctionContext) { - const uri = 'mongodb://root:nlwrr6cr@dbconn.sealoshzh.site:48953/?directConnection=true'; - const dbName = 'sealaf-cno56wxmj7'; + // const uri = process.env.BACKUP_MONGODB_URI; + // const dbName = 'sealaf-cno56wxmj7'; // let res = await db1.collection("users").where({ totalLevel: { $gt: 10000 } }).update({ totalLevel:0},{multi:true}); // return res; - let data = []; + // let data = []; // for(let i=0;i item.name === collectionName); - if (!exists) { - console.log(`collection "${collectionName}" not found`); - return; - } - for (let i = 0; i < 3; i++) { - console.log(data[i]); - const user = await db.collection(collectionName).findOne({ _id: data[i] }); - let data1 = { - endLevelNum: user.endLevelNum || 0, - totalLevel: user.totalLevel || user.levelAmount, - userLevel: user.userLevel || 0, - forcedUpdate: true, - } - if (user) { - //data1.coinAmount += 10000; - //console.log(data1); - let res22 = await db1.collection("users").where({ _id: data[i] }).update(data1); - //console.log(res22) - } - } - } catch (err) { - console.error('MongoDB error:', err); - } finally { - console.log("断开连接") - await client.close(); - } + // console.log(data); + // return data; + // const client = new MongoClient(uri); + // try { + // await client.connect(); + // const db = client.db(dbName); + // const collections = await db.listCollections().toArray(); + // const collectionName = 'users'; + // const exists = collections.some((item) => item.name === collectionName); + // if (!exists) { + // console.log(`collection "${collectionName}" not found`); + // return; + // } + // for (let i = 0; i < 3; i++) { + // console.log(data[i]); + // const user = await db.collection(collectionName).findOne({ _id: data[i] }); + // let data1 = { + // endLevelNum: user.endLevelNum || 0, + // totalLevel: user.totalLevel || user.levelAmount, + // userLevel: user.userLevel || 0, + // forcedUpdate: true, + // } + // if (user) { + // //data1.coinAmount += 10000; + // //console.log(data1); + // let res22 = await db1.collection("users").where({ _id: data[i] }).update(data1); + // //console.log(res22) + // } + // } + // } catch (err) { + // console.error('MongoDB error:', err); + // } finally { + // console.log("断开连接") + // await client.close(); + // } // let res = await db1.collection("users").where({ endLevelNum:99999999999999 }).get(); // let data=[]; // for(let i=0;i { }; /**获取订单*/ async function getOrder(outTradeNo) { - const url = `https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/${outTradeNo}?mchid=1719895437`; + const url = `https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/${outTradeNo}?mchid=${mchid}`; const nonceStr = crypto.randomBytes(16).toString('hex'); const timestamp = Math.floor(Date.now() / 1000).toString(); let au = await sign(outTradeNo, nonceStr, timestamp); @@ -126,13 +126,13 @@ async function getOrder(outTradeNo) { } } async function sign(outTradeNo, nonceStr, timestamp) { - const data = `GET\n/v3/pay/transactions/out-trade-no/${outTradeNo}?mchid=1719895437\n${timestamp}\n${nonceStr}\n\n` + const data = `GET\n/v3/pay/transactions/out-trade-no/${outTradeNo}?mchid=${mchid}\n${timestamp}\n${nonceStr}\n\n` // 创建签名对象 const sign = crypto.createSign('RSA-SHA256'); // 更新签名内容 sign.update(data); // 获取存储桶 - const bucket = cloud.storage.bucket('j3k323ol-colorblock-oss'); + const bucket = cloud.storage.bucket(process.env.WX_PAY_PRIVATE_KEY_BUCKET); // 获取文件列表 const res = await bucket.readFile('apiclient_key.pem'); const privateKeyPem = await res.Body.transformToString(); diff --git a/laf-cloud/functions/wx/iosorderPaySig.ts b/laf-cloud/functions/wx/iosorderPaySig.ts index 9972640..178c7a1 100644 --- a/laf-cloud/functions/wx/iosorderPaySig.ts +++ b/laf-cloud/functions/wx/iosorderPaySig.ts @@ -40,7 +40,7 @@ export default async function (ctx: FunctionContext) { }); let session_key = user.data.session_key; const signature = hmacSha256(session_key, signData); - let key = "GmsJF53hOi2CVkEeSg2Wlst9V9RDINKG"; + let key = process.env.WX_MIDAS_PAY_SIGN_KEY; let data = 'requestMidasPaymentGameItem' + '&' + signData; const paySig = hmacSha256(key, data); await db.collection("order").add({ diff --git a/laf-cloud/functions/wx/orderPaySig.ts b/laf-cloud/functions/wx/orderPaySig.ts index 1d6e260..e6af07c 100644 --- a/laf-cloud/functions/wx/orderPaySig.ts +++ b/laf-cloud/functions/wx/orderPaySig.ts @@ -40,7 +40,7 @@ export default async function (ctx: FunctionContext) { }); let session_key = user.data.session_key; const signature = hmacSha256(session_key, signData); - let key = "GmsJF53hOi2CVkEeSg2Wlst9V9RDINKG"; + let key = process.env.WX_MIDAS_PAY_SIGN_KEY; let data = 'requestMidasPaymentGameItem' + '&' + signData; const paySig = hmacSha256(key, data); await db.collection("order").add({ diff --git a/laf-cloud/functions/wx/payCallBack.ts b/laf-cloud/functions/wx/payCallBack.ts index 79b640b..217c9c1 100644 --- a/laf-cloud/functions/wx/payCallBack.ts +++ b/laf-cloud/functions/wx/payCallBack.ts @@ -151,9 +151,10 @@ async function sead(order, userInfo, ip) { console.log("未找到distinctId无法上传数数") return; } - let id = '95993f9ab6f1402a87abe5147827e5e0'; + + let id = '95993f9ab6f1402a87abe5147827e5e0';// 数数测试账号 if (userInfo.isDebug != "true") { - id = '40e3d5c5f2af49a4a074205564ce5dbb'; + id = '40e3d5c5f2af49a4a074205564ce5dbb';// 数数正式账号 } let teSDK = ThinkingData.initWithBatchMode(id, 'https://data.nika4fun.com/sync_data', { dryRun: false, // report data to TE or not