init
This commit is contained in:
@@ -1,55 +1,55 @@
|
||||
import { DEBUG_PRICE, SDK_37_CONST, STATUS } from "../../consts";
|
||||
import { RoleModel } from "../../db/Role";
|
||||
import { UserModel } from "../../db/User";
|
||||
import { LoginValidateData37 } from "../../domain/sdk";
|
||||
import { DicRMB } from "../../pubUtils/dictionary/DicRMB";
|
||||
import { nowSeconds } from "../../pubUtils/timeUtil";
|
||||
import { resResult } from "../../pubUtils/util";
|
||||
import { get37Md5SignA, isDebugPay } from "../../pubUtils/sdkUtil";
|
||||
import { pinus } from "pinus";
|
||||
import { gameData } from "../../pubUtils/data";
|
||||
|
||||
/**
|
||||
* 37支付下单
|
||||
*
|
||||
* @param {number} price 价格订单金额(分)
|
||||
* @param {string} message 商品信息
|
||||
* @param {string} localOrderID 本地订单号
|
||||
*
|
||||
*/
|
||||
export async function applyOrder37(localOrderID: string, roleId: string, productInfo: DicRMB) {
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let user = await UserModel.findUserByUid(role.userInfo.uid);
|
||||
if(!user || !user.channelInfo || !(<LoginValidateData37>user.channelInfo).uid)
|
||||
return {
|
||||
code: -1, resData: resResult(STATUS.CHANNEL_INFO_NOT_FOUND)
|
||||
}
|
||||
let gameCoin = productInfo.gameCoin;
|
||||
let ext = pinus.app.get('env');
|
||||
let body = {
|
||||
game_id: SDK_37_CONST.GAME_ID,
|
||||
uid: (<LoginValidateData37>user.channelInfo).uid,
|
||||
sid: role.serverId,
|
||||
actor_id: role.roleId,
|
||||
order_no: localOrderID,
|
||||
money: productInfo.price,
|
||||
game_coin: gameCoin,
|
||||
product_id: productInfo.channelProductID,
|
||||
subject: productInfo.message,
|
||||
time: nowSeconds(),
|
||||
ext
|
||||
}
|
||||
if(isDebugPay()) {
|
||||
body = {...body, money: DEBUG_PRICE}
|
||||
}
|
||||
|
||||
let sign = get37Md5SignA(body, SDK_37_CONST.PAY_KEY);
|
||||
|
||||
|
||||
return { code: 0, data: {
|
||||
gameCoin,
|
||||
timestamp: nowSeconds(),
|
||||
ext,
|
||||
sign: sign
|
||||
}};
|
||||
}
|
||||
import { DEBUG_PRICE, SDK_37_CONST, STATUS } from "@consts";
|
||||
import { RoleModel } from "@db/Role";
|
||||
import { UserModel } from "@db/User";
|
||||
import { LoginValidateData37 } from "@domain/sdk";
|
||||
import { DicRMB } from "@pubUtils/dictionary/DicRMB";
|
||||
import { nowSeconds } from "@pubUtils/timeUtil";
|
||||
import { resResult } from "@pubUtils/util";
|
||||
import { get37Md5SignA, isDebugPay } from "@pubUtils/sdkUtil";
|
||||
import { pinus } from "pinus";
|
||||
import { gameData } from "@pubUtils/data";
|
||||
|
||||
/**
|
||||
* 37支付下单
|
||||
*
|
||||
* @param {number} price 价格订单金额(分)
|
||||
* @param {string} message 商品信息
|
||||
* @param {string} localOrderID 本地订单号
|
||||
*
|
||||
*/
|
||||
export async function applyOrder37(localOrderID: string, roleId: string, productInfo: DicRMB) {
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let user = await UserModel.findUserByUid(role.userInfo.uid);
|
||||
if(!user || !user.channelInfo || !(<LoginValidateData37>user.channelInfo).uid)
|
||||
return {
|
||||
code: -1, resData: resResult(STATUS.CHANNEL_INFO_NOT_FOUND)
|
||||
}
|
||||
let gameCoin = productInfo.gameCoin;
|
||||
let ext = pinus.app.get('env');
|
||||
let body = {
|
||||
game_id: SDK_37_CONST.GAME_ID,
|
||||
uid: (<LoginValidateData37>user.channelInfo).uid,
|
||||
sid: role.serverId,
|
||||
actor_id: role.roleId,
|
||||
order_no: localOrderID,
|
||||
money: productInfo.price,
|
||||
game_coin: gameCoin,
|
||||
product_id: productInfo.channelProductID,
|
||||
subject: productInfo.message,
|
||||
time: nowSeconds(),
|
||||
ext
|
||||
}
|
||||
if(isDebugPay()) {
|
||||
body = {...body, money: DEBUG_PRICE}
|
||||
}
|
||||
|
||||
let sign = get37Md5SignA(body, SDK_37_CONST.PAY_KEY);
|
||||
|
||||
|
||||
return { code: 0, data: {
|
||||
gameCoin,
|
||||
timestamp: nowSeconds(),
|
||||
ext,
|
||||
sign: sign
|
||||
}};
|
||||
}
|
||||
|
||||
@@ -1,93 +1,93 @@
|
||||
|
||||
import path = require('path');
|
||||
import fs = require('fs');
|
||||
const Alipay = require('alipay-mobile').default
|
||||
/*
|
||||
包名:com.bantu.sgzzyz
|
||||
APPID:2021002142639438
|
||||
*/
|
||||
|
||||
//notify_url: 异步通知url
|
||||
//app_id: 开放平台 appid
|
||||
//appPrivKeyFile: 你的应用私钥
|
||||
//alipayPubKeyFile: 蚂蚁金服公钥
|
||||
const config = {
|
||||
app_id: '2021002142639438',
|
||||
appPrivKeyFile: fs.readFileSync(path.resolve(__dirname, '../../../../../key/alipay/rsa_private_key.pem')),
|
||||
alipayPubKeyFile: fs.readFileSync(path.resolve(__dirname, '../../../../../key/alipay/rsa_public_key.pem'))
|
||||
}
|
||||
|
||||
|
||||
const service = new Alipay(config)
|
||||
|
||||
/**
|
||||
* 支付宝下单
|
||||
*
|
||||
* @param {number} price 订单总金额,单位为元,精确到小数点后两位
|
||||
* @param {string} message 商品信息
|
||||
* @param {string} localOrderID 本地订单号
|
||||
*
|
||||
*/
|
||||
export async function applyOrderALI(localOrderID: string, price: number, message: string) {
|
||||
const data = {
|
||||
subject: message,
|
||||
out_trade_no: localOrderID,
|
||||
total_amount: price.toFixed(2).toString()
|
||||
}
|
||||
console.log('applyOrderALI :', data)
|
||||
let result = await service.createOrder(data)
|
||||
|
||||
// { code: 0,
|
||||
// message: '请求成功',
|
||||
// data:
|
||||
// 'app_id=2021002142639438&biz_content=%7B%22subject%22%3A%22%E8%B5%B5%E4%BA%91%E4%BC%A0%E8%B4%AD%E4%B9%B0%E5%85%83%E5%AE%9D60%22%2C%22out_trade_no%22%3A%22bwnNLGfdCylflxKf54bEpcwyEbq7xygp%22%2C%22total_amount%22%3A%226.00%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%7D&charset=utf-8&method=alipay.trade.app.pay&sign_type=RSA2×tamp=2021-05-12%2018%3A40%3A25&version=1.0&sign=S4U6JzSUiCSMvAbXeiJ2m2AQ%2BfCSr4VE4VNN9QEZtplgWIO51HIGhL24BpR4aj7mMfWO%2BqaWQnU0Fe8Uki960smBdj0%2FDpuztA7%2BIBWHK1Qj69%2FLhDNLoHZgO41jQJjIOVI0gWt1KaDlG2%2B52ghswqcZN%2FkFLwfMZCMEph3eg3aofq1mmwRbqAh8Sepoy9nCd24CmMUIbNe%2FmcxVg3xvYcWXnneWWHu%2FFbnaeZtynoHVhXqqhjFZSrxdk8lo5qyTXkE1ZoUrhJz918E2rArwzZeUL09ncPshHHvX6AygXp5BtV4clwTY0OY5yzOEXboluR5YmSaVXn0VkTWJZCTWTQ%3D%3D'
|
||||
// }
|
||||
console.log('applyOrderALI result: ', result)
|
||||
if (result.code == 0) {
|
||||
return { code: 0, data: result.data };
|
||||
}
|
||||
return { code: -1, data: JSON.stringify(result) };
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 支付宝查询支付结果
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {string} roleId 角色Id
|
||||
* @param {string} localOrderID 本地订单号
|
||||
*
|
||||
*/
|
||||
export async function checkOrderALI(localOrderID: string) {
|
||||
let data = {
|
||||
out_trade_no: localOrderID,
|
||||
}
|
||||
console.log('checkOrderALI :', data)
|
||||
|
||||
let result = await service.queryOrder(data)
|
||||
console.log('checkOrderALI result: ', result)
|
||||
// {
|
||||
// 0|app | code: '0',
|
||||
// 0|app | data: {
|
||||
// 0|app | code: '10000',
|
||||
// 0|app | msg: 'Success',
|
||||
// 0|app | buyer_logon_id: '525***@qq.com',
|
||||
// 0|app | buyer_pay_amount: '0.00',
|
||||
// 0|app | buyer_user_id: '2088302819007765',
|
||||
// 0|app | invoice_amount: '0.00',
|
||||
// 0|app | out_trade_no: 'JbyWyR1SIVIw9ArxvHAgte6tmnIzSRea',
|
||||
// 0|app | point_amount: '0.00',
|
||||
// 0|app | receipt_amount: '0.00',
|
||||
// 0|app | send_pay_date: '2019-09-29 18:32:13',
|
||||
// 0|app | total_amount: '1.00',
|
||||
// 0|app | trade_no: '2019092922001407760553648380',
|
||||
// 0|app | trade_status: 'TRADE_SUCCESS'
|
||||
// 0|app | },
|
||||
// 0|app | message: 'success'
|
||||
// 0|app | }
|
||||
if ((result.code == '0') && (result.message == "success")) {
|
||||
return { code: 1, data: result.data };
|
||||
}
|
||||
return { code: 0, data: JSON.stringify(result) };
|
||||
}
|
||||
|
||||
import path = require('path');
|
||||
import fs = require('fs');
|
||||
const Alipay = require('alipay-mobile').default
|
||||
/*
|
||||
包名:com.bantu.sgzzyz
|
||||
APPID:2021002142639438
|
||||
*/
|
||||
|
||||
//notify_url: 异步通知url
|
||||
//app_id: 开放平台 appid
|
||||
//appPrivKeyFile: 你的应用私钥
|
||||
//alipayPubKeyFile: 蚂蚁金服公钥
|
||||
const config = {
|
||||
app_id: '2021002142639438',
|
||||
appPrivKeyFile: fs.readFileSync(path.resolve(__dirname, '../../../../../key/alipay/rsa_private_key.pem')),
|
||||
alipayPubKeyFile: fs.readFileSync(path.resolve(__dirname, '../../../../../key/alipay/rsa_public_key.pem'))
|
||||
}
|
||||
|
||||
|
||||
const service = new Alipay(config)
|
||||
|
||||
/**
|
||||
* 支付宝下单
|
||||
*
|
||||
* @param {number} price 订单总金额,单位为元,精确到小数点后两位
|
||||
* @param {string} message 商品信息
|
||||
* @param {string} localOrderID 本地订单号
|
||||
*
|
||||
*/
|
||||
export async function applyOrderALI(localOrderID: string, price: number, message: string) {
|
||||
const data = {
|
||||
subject: message,
|
||||
out_trade_no: localOrderID,
|
||||
total_amount: price.toFixed(2).toString()
|
||||
}
|
||||
console.log('applyOrderALI :', data)
|
||||
let result = await service.createOrder(data)
|
||||
|
||||
// { code: 0,
|
||||
// message: '请求成功',
|
||||
// data:
|
||||
// 'app_id=2021002142639438&biz_content=%7B%22subject%22%3A%22%E8%B5%B5%E4%BA%91%E4%BC%A0%E8%B4%AD%E4%B9%B0%E5%85%83%E5%AE%9D60%22%2C%22out_trade_no%22%3A%22bwnNLGfdCylflxKf54bEpcwyEbq7xygp%22%2C%22total_amount%22%3A%226.00%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%7D&charset=utf-8&method=alipay.trade.app.pay&sign_type=RSA2×tamp=2021-05-12%2018%3A40%3A25&version=1.0&sign=S4U6JzSUiCSMvAbXeiJ2m2AQ%2BfCSr4VE4VNN9QEZtplgWIO51HIGhL24BpR4aj7mMfWO%2BqaWQnU0Fe8Uki960smBdj0%2FDpuztA7%2BIBWHK1Qj69%2FLhDNLoHZgO41jQJjIOVI0gWt1KaDlG2%2B52ghswqcZN%2FkFLwfMZCMEph3eg3aofq1mmwRbqAh8Sepoy9nCd24CmMUIbNe%2FmcxVg3xvYcWXnneWWHu%2FFbnaeZtynoHVhXqqhjFZSrxdk8lo5qyTXkE1ZoUrhJz918E2rArwzZeUL09ncPshHHvX6AygXp5BtV4clwTY0OY5yzOEXboluR5YmSaVXn0VkTWJZCTWTQ%3D%3D'
|
||||
// }
|
||||
console.log('applyOrderALI result: ', result)
|
||||
if (result.code == 0) {
|
||||
return { code: 0, data: result.data };
|
||||
}
|
||||
return { code: -1, data: JSON.stringify(result) };
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 支付宝查询支付结果
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {string} roleId 角色Id
|
||||
* @param {string} localOrderID 本地订单号
|
||||
*
|
||||
*/
|
||||
export async function checkOrderALI(localOrderID: string) {
|
||||
let data = {
|
||||
out_trade_no: localOrderID,
|
||||
}
|
||||
console.log('checkOrderALI :', data)
|
||||
|
||||
let result = await service.queryOrder(data)
|
||||
console.log('checkOrderALI result: ', result)
|
||||
// {
|
||||
// 0|app | code: '0',
|
||||
// 0|app | data: {
|
||||
// 0|app | code: '10000',
|
||||
// 0|app | msg: 'Success',
|
||||
// 0|app | buyer_logon_id: '525***@qq.com',
|
||||
// 0|app | buyer_pay_amount: '0.00',
|
||||
// 0|app | buyer_user_id: '2088302819007765',
|
||||
// 0|app | invoice_amount: '0.00',
|
||||
// 0|app | out_trade_no: 'JbyWyR1SIVIw9ArxvHAgte6tmnIzSRea',
|
||||
// 0|app | point_amount: '0.00',
|
||||
// 0|app | receipt_amount: '0.00',
|
||||
// 0|app | send_pay_date: '2019-09-29 18:32:13',
|
||||
// 0|app | total_amount: '1.00',
|
||||
// 0|app | trade_no: '2019092922001407760553648380',
|
||||
// 0|app | trade_status: 'TRADE_SUCCESS'
|
||||
// 0|app | },
|
||||
// 0|app | message: 'success'
|
||||
// 0|app | }
|
||||
if ((result.code == '0') && (result.message == "success")) {
|
||||
return { code: 1, data: result.data };
|
||||
}
|
||||
return { code: 0, data: JSON.stringify(result) };
|
||||
}
|
||||
|
||||
@@ -1,94 +1,94 @@
|
||||
|
||||
import tenpay = require('tenpay');
|
||||
import path = require('path');
|
||||
|
||||
/*
|
||||
包名:com.bantu.sgzzyz
|
||||
APPID:wx1d3cd5cd2f065358
|
||||
AppSecret:ebf099c41da57edf8693b5bb234d9b31
|
||||
商户号:1272966801
|
||||
APISECRET:ABCabc328BantuPKU726BANTUMPRCghb
|
||||
*/
|
||||
|
||||
const config = {
|
||||
appid: 'wx1d3cd5cd2f065358',
|
||||
mchid: '1272966801',
|
||||
partnerKey: 'ABCabc328BantuPKU726BANTUMPRCghb',
|
||||
pfx: require('fs').readFileSync(path.resolve(__dirname, '../../../../../key/weixinpay/apiclient_cert.p12')),
|
||||
notify_url: "https://" + "10.29.176.166" + "/order/weixinpaycallback",//支付回调网址
|
||||
spbill_create_ip: '127.0.0.1'
|
||||
};
|
||||
// 方式一
|
||||
const api = new tenpay(config);
|
||||
// 调试模式
|
||||
// const api = new tenpay(config, true);
|
||||
// 沙盒模式(用于微信支付验收)
|
||||
// const sandboxAPI = await tenpay.sandbox(config);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 微信下单
|
||||
*
|
||||
* @param {number} price 价格订单金额(分)
|
||||
* @param {string} message 商品信息
|
||||
* @param {string} localOrderID 本地订单号
|
||||
*
|
||||
*/
|
||||
export async function applyOrderWX(localOrderID: string, price: number, message: string) {
|
||||
let data = {
|
||||
out_trade_no: localOrderID,
|
||||
body: message,//'商品简单描述',
|
||||
total_fee: price,//'订单金额(分)',
|
||||
}
|
||||
console.log('applyOrderWX :', data)
|
||||
let result = await api.getAppParams(data)
|
||||
// { appid: 'wx1d3cd5cd2f065358',
|
||||
// partnerid: '1272966801',
|
||||
// prepayid: 'wx12171213153829021f7cfe9413f0a20000',//微信订单号
|
||||
// package: 'Sign=WXPay',
|
||||
// noncestr: 'OohMyaHNK0iP77uh',
|
||||
// timestamp: '1620810734',
|
||||
// sign: '7A1B41C577E78602344D03DE4A2F7B0A' }
|
||||
console.log('applyOrderWX result: ', result)
|
||||
if (result.appid == config.appid && result.partnerid == config.mchid) {
|
||||
return { code: 0, data: result };
|
||||
}
|
||||
return { code: -1, data: JSON.stringify(result) };
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 微信查询支付结果
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {string} roleId 角色Id
|
||||
* @param {string} localOrderID 本地订单号
|
||||
*
|
||||
*/
|
||||
export async function checkOrderWX(localOrderID: string) {
|
||||
let data = {
|
||||
out_trade_no: localOrderID,
|
||||
}
|
||||
console.log('checkOrderWX :', data)
|
||||
let result = await api.orderQuery(data)
|
||||
// { return_code: 'SUCCESS',
|
||||
// return_msg: 'OK',
|
||||
// result_code: 'SUCCESS',
|
||||
// mch_id: '1272966801',
|
||||
// appid: 'wx1d3cd5cd2f065358',
|
||||
// device_info: '',
|
||||
// trade_state: 'NOTPAY',
|
||||
// total_fee: '6',
|
||||
// out_trade_no: 'nMeyvwjJSmNXPmfGcr6kzalTR3jlp7jW',
|
||||
// trade_state_desc: '订单未支付',
|
||||
// nonce_str: 'aJevQOtSDgvNDbtQ',
|
||||
// sign: '955CE5F8AA2F046DA66E0A5DA56B338A' }
|
||||
console.log('checkOrderWX result: ', result)
|
||||
if (result.appid == config.appid && result.mch_id == config.mchid) {
|
||||
return { code: 1, data: result };
|
||||
}
|
||||
return { code: 0, data: JSON.stringify(result) };
|
||||
}
|
||||
|
||||
import tenpay = require('tenpay');
|
||||
import path = require('path');
|
||||
|
||||
/*
|
||||
包名:com.bantu.sgzzyz
|
||||
APPID:wx1d3cd5cd2f065358
|
||||
AppSecret:ebf099c41da57edf8693b5bb234d9b31
|
||||
商户号:1272966801
|
||||
APISECRET:ABCabc328BantuPKU726BANTUMPRCghb
|
||||
*/
|
||||
|
||||
const config = {
|
||||
appid: 'wx1d3cd5cd2f065358',
|
||||
mchid: '1272966801',
|
||||
partnerKey: 'ABCabc328BantuPKU726BANTUMPRCghb',
|
||||
pfx: require('fs').readFileSync(path.resolve(__dirname, '../../../../../key/weixinpay/apiclient_cert.p12')),
|
||||
notify_url: "https://" + "10.29.176.166" + "/order/weixinpaycallback",//支付回调网址
|
||||
spbill_create_ip: '127.0.0.1'
|
||||
};
|
||||
// 方式一
|
||||
const api = new tenpay(config);
|
||||
// 调试模式
|
||||
// const api = new tenpay(config, true);
|
||||
// 沙盒模式(用于微信支付验收)
|
||||
// const sandboxAPI = await tenpay.sandbox(config);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 微信下单
|
||||
*
|
||||
* @param {number} price 价格订单金额(分)
|
||||
* @param {string} message 商品信息
|
||||
* @param {string} localOrderID 本地订单号
|
||||
*
|
||||
*/
|
||||
export async function applyOrderWX(localOrderID: string, price: number, message: string) {
|
||||
let data = {
|
||||
out_trade_no: localOrderID,
|
||||
body: message,//'商品简单描述',
|
||||
total_fee: price,//'订单金额(分)',
|
||||
}
|
||||
console.log('applyOrderWX :', data)
|
||||
let result = await api.getAppParams(data)
|
||||
// { appid: 'wx1d3cd5cd2f065358',
|
||||
// partnerid: '1272966801',
|
||||
// prepayid: 'wx12171213153829021f7cfe9413f0a20000',//微信订单号
|
||||
// package: 'Sign=WXPay',
|
||||
// noncestr: 'OohMyaHNK0iP77uh',
|
||||
// timestamp: '1620810734',
|
||||
// sign: '7A1B41C577E78602344D03DE4A2F7B0A' }
|
||||
console.log('applyOrderWX result: ', result)
|
||||
if (result.appid == config.appid && result.partnerid == config.mchid) {
|
||||
return { code: 0, data: result };
|
||||
}
|
||||
return { code: -1, data: JSON.stringify(result) };
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 微信查询支付结果
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {string} roleId 角色Id
|
||||
* @param {string} localOrderID 本地订单号
|
||||
*
|
||||
*/
|
||||
export async function checkOrderWX(localOrderID: string) {
|
||||
let data = {
|
||||
out_trade_no: localOrderID,
|
||||
}
|
||||
console.log('checkOrderWX :', data)
|
||||
let result = await api.orderQuery(data)
|
||||
// { return_code: 'SUCCESS',
|
||||
// return_msg: 'OK',
|
||||
// result_code: 'SUCCESS',
|
||||
// mch_id: '1272966801',
|
||||
// appid: 'wx1d3cd5cd2f065358',
|
||||
// device_info: '',
|
||||
// trade_state: 'NOTPAY',
|
||||
// total_fee: '6',
|
||||
// out_trade_no: 'nMeyvwjJSmNXPmfGcr6kzalTR3jlp7jW',
|
||||
// trade_state_desc: '订单未支付',
|
||||
// nonce_str: 'aJevQOtSDgvNDbtQ',
|
||||
// sign: '955CE5F8AA2F046DA66E0A5DA56B338A' }
|
||||
console.log('checkOrderWX result: ', result)
|
||||
if (result.appid == config.appid && result.mch_id == config.mchid) {
|
||||
return { code: 1, data: result };
|
||||
}
|
||||
return { code: 0, data: JSON.stringify(result) };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user