已更新

This commit is contained in:
COMPUTER\EDY 2026-07-10 19:44:29 +08:00
parent 3fa0238fbc
commit ae2a1feccb
8 changed files with 69 additions and 55 deletions

View File

@ -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({

View File

@ -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("充值失败");

View File

@ -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 数数平台
/*
*

View File

@ -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

View File

@ -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("充值失败");

View File

@ -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("充值失败");

View File

@ -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("充值失败");

View File

@ -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;
}
}