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