diff --git a/assets/Script/GameManager.ts b/assets/Script/GameManager.ts index 9dbe9b1..5d27ee5 100644 --- a/assets/Script/GameManager.ts +++ b/assets/Script/GameManager.ts @@ -873,6 +873,16 @@ export default class GameManager extends cc.Component { }) }, 4000); + //@ts-ignore + wx.onAddToFavorites(() => { + console.log("收藏成功"); + MiniGameSdk.API.tencent_ADD_TO_WISHLIST(); + return { + title: '收藏标题', + imageUrl: '' // 图片 URL + } + }) + // 设置分享到朋友圈 //@ts-ignore // wx.updateShareMenu({ diff --git a/assets/Script/Revive.ts b/assets/Script/Revive.ts index 6cc54e5..89a6c61 100644 --- a/assets/Script/Revive.ts +++ b/assets/Script/Revive.ts @@ -256,9 +256,7 @@ export default class Revive extends cc.Component { console.log("错误原因:", res.errMsg); if (res.errMsg && res.errMsg.indexOf("fail App Store") !== -1) { console.log("走ios旧支付"); - setTimeout(() => { - this.iosOldPay(price, productId); - }, 500); + this.iosOldPay(price, productId); return; } MiniGameSdk.API.showToast("充值失败"); diff --git a/assets/Script/Sdk/MiniGameSdk.ts b/assets/Script/Sdk/MiniGameSdk.ts index 01b7e17..86ec9b5 100644 --- a/assets/Script/Sdk/MiniGameSdk.ts +++ b/assets/Script/Sdk/MiniGameSdk.ts @@ -1563,6 +1563,10 @@ export namespace MiniGameSdk { if (API._tencent) API._tencent.onRegister(); } + static tencent_ADD_TO_WISHLIST() { + if (API._tencent) API._tencent.onAddToWishlist(); + } + //#region 数数平台 /* * 数数平台初始化以及登录 diff --git a/assets/Script/module/Config/GameConfig.ts b/assets/Script/module/Config/GameConfig.ts index a96af35..be130d4 100644 --- a/assets/Script/module/Config/GameConfig.ts +++ b/assets/Script/module/Config/GameConfig.ts @@ -305,7 +305,7 @@ export class GameConfig { vibrateOpen: true, //震动 coinnum: 0, //每局的金币数 paid_user: false, //是否是付费用户 - version: "1.0.04", //版本号 + version: "1.0.15", //版本号 shushu_DistinctId: "", //数数访客ID shushu_AccountId: "", //数数账号ID uid: "", //用户和后端唯一id diff --git a/assets/action_bundle/script/NewbieGift.ts b/assets/action_bundle/script/NewbieGift.ts index fc69171..5481fdc 100644 --- a/assets/action_bundle/script/NewbieGift.ts +++ b/assets/action_bundle/script/NewbieGift.ts @@ -394,9 +394,7 @@ export default class NewbieGift extends cc.Component { console.log("错误原因:", res.errMsg); if (res.errMsg && res.errMsg.indexOf("fail App Store") !== -1) { console.log("走ios旧支付"); - setTimeout(() => { - this.iosOldPay(price, productId); - }, 500); + this.iosOldPay(price, productId); return; } MiniGameSdk.API.showToast("充值失败"); diff --git a/assets/shop/script/passCheck.ts b/assets/shop/script/passCheck.ts index d61c3c9..1239cea 100644 --- a/assets/shop/script/passCheck.ts +++ b/assets/shop/script/passCheck.ts @@ -600,9 +600,7 @@ export default class passCheck extends cc.Component { console.log("错误原因:", res.errMsg); if (res.errMsg && res.errMsg.indexOf("fail App Store") !== -1) { console.log("走ios旧支付"); - setTimeout(() => { - this.iosOldPay(price, productId); - }, 500); + this.iosOldPay(price, productId); return; } MiniGameSdk.API.showToast("充值失败"); diff --git a/assets/shop/script/shop.ts b/assets/shop/script/shop.ts index 4052f19..17737be 100644 --- a/assets/shop/script/shop.ts +++ b/assets/shop/script/shop.ts @@ -629,9 +629,7 @@ export default class NewClass extends cc.Component { console.log("错误原因:", res.errMsg); if (res.errMsg && res.errMsg.indexOf("fail App Store") !== -1) { console.log("走ios旧支付"); - setTimeout(() => { - this.iosOldPay(price, productId); - }, 500); + this.iosOldPay(price, productId); return; } MiniGameSdk.API.showToast("充值失败"); diff --git a/server/laf-cloud/functions/wx/KeFuInfo.ts b/server/laf-cloud/functions/wx/KeFuInfo.ts index a1fc7b6..321e71f 100644 --- a/server/laf-cloud/functions/wx/KeFuInfo.ts +++ b/server/laf-cloud/functions/wx/KeFuInfo.ts @@ -1,52 +1,55 @@ import cloud from '@lafjs/cloud' const token = "nika123"; -const EncodingAESKey ="XcdOFaZOQjmyBqYHxWAITtrmq11YaZQ63DeEZAAgYJt"; -const mchid ="1719895437";//商户id -const serialNo ="2A97ED6ED441E55600EBC8830B9EC889ED41496E";//证书序列号 -const appid ="wxdd145ced49158a1e"; +const EncodingAESKey = "XcdOFaZOQjmyBqYHxWAITtrmq11YaZQ63DeEZAAgYJt"; +const mchid = "1719895437";//商户id +const serialNo = "2A97ED6ED441E55600EBC8830B9EC889ED41496E";//证书序列号 +const appid = "wx30f74367b3d3e7a6"; import crypto from 'crypto'; const db = cloud.database(); export default async function (ctx: FunctionContext) { - try{ + console.log(ctx.body); + //console.log(ctx.query);; + try { let openid = ctx.body.FromUserName; //console.log(openid); const data = JSON.parse(ctx.body.SessionFrom); //console.log(data); + console.log(data); if (data.tpye == "ios") { await PostMsg(openid, "点击下方页面进行充值"); await PostImg(openid, data.outTradeNo, data.propName, data.count, data.price); } - }catch(e){ - console.error("ios客服充值参数错误:"+ctx.body.SessionFrom); + } catch (e) { + console.error("ios客服充值参数错误:" + ctx.body.SessionFrom); console.log(ctx.body); } - - return {data:"scuess"}; + //return ctx.query.echostr; + return { data: "scuess" }; } /**获取订单*/ -async function getOrder(openid, toatal, outTradeNo, timestamp, nonceStr){ +async function getOrder(openid, toatal, outTradeNo, timestamp, nonceStr) { const url = "https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi"; // 生成随机字符串和时间戳 const body = { "appid": appid, "mchid": mchid, - "description": "五彩消消乐道具购买", + "description": "消消王者道具购买", "out_trade_no": outTradeNo, - "notify_url": "http://laf.nika4games.com/wx/iosPayCall", + "notify_url": "https://q6rvwvtnga.sealoshzh.site/wx/iosPayCall", "amount": { "total": Number(toatal), "currency": "CNY" }, "payer": { "openid": openid } } - let ret=await sign(nonceStr,timestamp,body); + let ret = await sign(nonceStr, timestamp, body); const res = await fetch(url, { method: 'POST', headers: { - 'Authorization':ret, - 'Accept':'application/json', + 'Authorization': ret, + 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify(body) }) - if(res.ok){ + if (res.ok) { const data = await res.json().catch(async () => { //如果不是JSON,尝试读取文本 return await res.text().catch(() => 'Empty response'); @@ -55,7 +58,7 @@ async function getOrder(openid, toatal, outTradeNo, timestamp, nonceStr){ } return null; } -async function sign(nonceStr,timestamp,body) { +async function sign(nonceStr, timestamp, body) { const data = `POST\n/v3/pay/transactions/jsapi\n${timestamp}\n${nonceStr}\n${JSON.stringify(body)}\n`; // 创建签名对象 const sign = crypto.createSign('RSA-SHA256'); @@ -86,6 +89,7 @@ async function frontsign(data) { // 获取文件列表 const res = await bucket.readFile('apiclient_key.pem'); const privateKeyPem = await res.Body.transformToString(); + //console.error(privateKeyPem); // 使用私钥签名(PKCS1 填充) const signature = sign.sign({ key: privateKeyPem, @@ -94,20 +98,20 @@ async function frontsign(data) { // 构建Authorization头 return signature } -const propName={ +const propName = { gold_1: "金币包1", gold_2: "金币包2", gold_3: "金币包3", gold_4: "金币包4", gold_5: "金币包5", gold_6: "金币包6", - unlimited_health_bundle_1:"无限体力组合包1", - unlimited_health_bundle_2:"无限体力组合包2", - unlimited_health_bundle_3:"无限体力组合包3", - freeze_in_game:"局内购买冻结", - hammer_in_game:"局内购买锤子", - wand_in_gamerefill:"局内购买魔棒", - health:"补满体力" + unlimited_health_bundle_1: "无限体力组合包1", + unlimited_health_bundle_2: "无限体力组合包2", + unlimited_health_bundle_3: "无限体力组合包3", + freeze_in_game: "局内购买冻结", + hammer_in_game: "局内购买锤子", + wand_in_gamerefill: "局内购买魔棒", + health: "补满体力" }; async function PostMsg(OpenId, msg) { @@ -142,26 +146,26 @@ async function PostImg(OpenId, outTradeNo, name, count, price) { const url = `https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=${token}`; const nonceStr = crypto.randomBytes(16).toString('hex'); const timestamp = Math.floor(Date.now() / 1000).toString(); - const total=count*price; - let prepay_id = await getOrder(OpenId,total,outTradeNo,timestamp,nonceStr); - let frontBody={ + const total = count * price; + let prepay_id = await getOrder(OpenId, total, outTradeNo, timestamp, nonceStr); + let frontBody = { "appId": appid, //公众号ID,由商户传入 "timeStamp": timestamp, //时间戳,自1970年以来的秒数 "nonceStr": nonceStr, //随机串 - "package": "prepay_id=" + prepay_id + "package": "prepay_id=" + prepay_id } const data1 = `${frontBody.appId}\n${frontBody.timeStamp}\n${frontBody.nonceStr}\n${frontBody.package}\n`; - let paySign=await frontsign(data1); + let paySign = await frontsign(data1); - let user = await db.collection("users").where({ openid: OpenId }).update({iosTime:frontBody.timeStamp}); - let param={ - name:propName[name], - openid:OpenId, + let user = await db.collection("users").where({ openid: OpenId }).update({ iosTime: frontBody.timeStamp }); + let param = { + name: propName[name], + openid: OpenId, outTradeNo: outTradeNo, - time:timestamp, - quantity:count, - price:price, - body:{ + time: timestamp, + quantity: count, + price: price, + body: { "appId": frontBody.appId, //公众号ID,由商户传入 "timeStamp": frontBody.timeStamp, //时间戳,自1970年以来的秒数 "nonceStr": frontBody.nonceStr, //随机串 @@ -177,6 +181,9 @@ async function PostImg(OpenId, outTradeNo, name, count, price) { itemCount: count, goodsPrice: Number(price), time: Date.now(), + orderTime: new Date(Date.now() + 8 * 3600000), + chargeTime: 0, + getTime: 0, type: "ios", state: 0, }); @@ -185,8 +192,8 @@ async function PostImg(OpenId, outTradeNo, name, count, price) { "msgtype": "link", "link": { "title": "点我支付", - "description": "金额:" + (total/100).toFixed(2) + "元", - "url": `https://pay.nika4games.com/order2.html#data=${encodeURIComponent(JSON.stringify(param))}`, + "description": "金额:" + (total / 100).toFixed(2) + "元", + "url": `https://pay.nika4games.com/order3.html#data=${encodeURIComponent(JSON.stringify(param))}`, "thumb_url": "https://static-host-j3k323ol-colorblock-oss.sealoshzh.site/icon.jpg" } } @@ -199,7 +206,8 @@ async function PostImg(OpenId, outTradeNo, name, count, price) { body: JSON.stringify(data) }) const data11 = await res.json(); - if (data11.errcode == 40001){ + console.log(data11); + if (data11.errcode == 40001) { console.error("未获取到正确token,重新发送请求"); let res = await getWxToken(); await PostMsg(OpenId, "点击下方页面进行充值"); @@ -220,7 +228,7 @@ async function getWxToken() { cloud.shared.set('wxaccess_token', ret.data.access_token); return ret.data.access_token; } else { - //access_token = null; + //access_token = nul l; return null; } }