增加game svr上报
This commit is contained in:
parent
c1d01f4ab0
commit
d2e2337df0
@ -11,6 +11,7 @@ GOOGLE_OAUTH_CLIENT_IOS="53206975661-qan0rnefniegjv53ohild375pv0p7ekd.apps.googl
|
||||
DB_MAIN=mongodb://localhost/wallet-development
|
||||
|
||||
EMAIL_VERIFY_URL="https://wallet.cebggame.com"
|
||||
EMAIL_SERVER='http://127.0.0.1:3087'
|
||||
|
||||
ALCHEMY_APPID="f83Is2y7L425rxl8"
|
||||
ALCHEMY_APP_SECRET="4Yn8RkxDXN71Q3p0"
|
||||
@ -41,3 +42,6 @@ BSC_WALLET='0x50A8e60041A206AcaA5F844a1104896224be6F39'
|
||||
PAY_TRANSFER_CB_URL='http://127.0.0.1:3007/api/internal/update_task'
|
||||
# 链端回调hash的ket
|
||||
HASH_SALT='iG4Rpsa)6U31$H#^T85$^^3'
|
||||
|
||||
# 游戏服, 支付上报地址
|
||||
GAME_PAY_CB_URL='https://game2006api-test.kingsome.cn/webapp/index.php?c=Shop&a=buyGoodsDirect‘
|
@ -6,16 +6,17 @@ import { createOrder, createPageSign, queryFiat, queryPrice, refreshToken } from
|
||||
import { generateKVStr } from 'utils/net.util'
|
||||
import { PayRecord, PayStatus } from 'modules/PayRecord'
|
||||
import { PriceSvr } from 'service/price.svr'
|
||||
import { reportPayResult } from 'service/game.svr'
|
||||
|
||||
const CALL_BACK_URL = `${process.env.ALCHEMY_PAY_CB_URL}/pay/out/alchemy/buycb`
|
||||
class AlchemyController extends BaseController {
|
||||
@router('post /pay/alchemy/buy')
|
||||
async beginApiPay(req, res) {
|
||||
const user = req.user
|
||||
const { network, crypto, address, fiat, fiatAmount, country } = req.params
|
||||
const { network, crypto, address, fiat, fiatAmount, payWayCode, country, accountId, orderId } = req.params
|
||||
if (fiat || fiatAmount || country) {
|
||||
if (!fiat || !fiatAmount || !country) {
|
||||
throw new ZError(11, 'fiat, fiatAmount and country must be provided')
|
||||
if (!fiat || !fiatAmount || !country || !payWayCode) {
|
||||
throw new ZError(11, 'fiat, fiatAmount payWayCode and country must be provided')
|
||||
}
|
||||
}
|
||||
if (network || crypto) {
|
||||
@ -30,7 +31,14 @@ class AlchemyController extends BaseController {
|
||||
throw new ZError(10, 'fetch pay token error')
|
||||
}
|
||||
const { id, email, accessToken } = tokenResult.data
|
||||
let record = new PayRecord({ account: user.id, address, network, crypto })
|
||||
let record = new PayRecord({
|
||||
account: user.id,
|
||||
address,
|
||||
network,
|
||||
crypto,
|
||||
gameAccountId: accountId,
|
||||
gameOrderId: orderId,
|
||||
})
|
||||
if (fiat) record.fiat = fiat
|
||||
if (fiatAmount) record.fiatAmount = fiatAmount
|
||||
if (country) record.country = country
|
||||
@ -44,7 +52,7 @@ class AlchemyController extends BaseController {
|
||||
depositType: '2',
|
||||
address: address,
|
||||
network: record.network,
|
||||
payWayCode: '10001',
|
||||
payWayCode,
|
||||
alpha2: record.country,
|
||||
callbackUrl: CALL_BACK_URL,
|
||||
merchantName: 'CEBG',
|
||||
@ -55,10 +63,15 @@ class AlchemyController extends BaseController {
|
||||
record.outData = payRes.data
|
||||
if (payRes.success) {
|
||||
record.outOrderId = payRes.data.orderNo
|
||||
await record.save()
|
||||
} else {
|
||||
record.status = PayStatus.FAIL
|
||||
await record.save()
|
||||
setImmediate(() => {
|
||||
reportPayResult(record)
|
||||
})
|
||||
}
|
||||
record.save()
|
||||
|
||||
return { url: payRes.data.payUrl }
|
||||
}
|
||||
@router('post /pay/alchemy/buypage')
|
||||
|
@ -6,6 +6,7 @@ import { checkPayResultSign, checkSimpleSign } from 'service/alchemy.svr'
|
||||
import { PayRecord, PayStatus } from 'modules/PayRecord'
|
||||
import { TransferQueue } from 'queue/transfer.queue'
|
||||
import { TransferRecord } from 'modules/TransferRecord'
|
||||
import { reportPayResult } from 'service/game.svr'
|
||||
|
||||
let errorRes = function (msg: string) {
|
||||
return {
|
||||
@ -59,6 +60,9 @@ class AlchemyOutController extends BaseController {
|
||||
record.outData = req.params
|
||||
record.status = status == 'PAY_SUCCESS' ? PayStatus.SUCCESS : PayStatus.FAIL
|
||||
await record.save()
|
||||
setImmediate(() => {
|
||||
reportPayResult(record)
|
||||
})
|
||||
logger.info(`alchemy callback success, pay finished`)
|
||||
return {}
|
||||
}
|
||||
|
@ -48,7 +48,9 @@ class MainController extends BaseController {
|
||||
const openId = payload.sub
|
||||
let data: any = {}
|
||||
if (payload.email) data.email = payload.email
|
||||
if (payload.email_verified !== undefined) data.emailVerified = payload.email_verified
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
if (payload.email_verified !== undefined) data.emailVerified = payload.email_verified
|
||||
}
|
||||
if (payload.locale) data.locale = payload.locale
|
||||
if (payload.name) data.nickname = payload.name
|
||||
if (payload.picture) data.avatar = payload.picture
|
||||
|
@ -37,6 +37,12 @@ class VerifyController extends BaseController {
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过邮件中的验证码验证
|
||||
* @param req
|
||||
* @param res
|
||||
* @returns
|
||||
*/
|
||||
@router('post /email/verify_by_code')
|
||||
async verifyEmailByCode(req, res) {
|
||||
let user = req.user
|
||||
|
@ -33,13 +33,16 @@ class WalletController extends BaseController {
|
||||
return { email: user.emailReal, verified: 1 }
|
||||
}
|
||||
if (user.email && user.emailVerified) {
|
||||
let needSave = false
|
||||
if (!user.verified) {
|
||||
needSave = true
|
||||
user.verified = true
|
||||
}
|
||||
if (!user.emailReal) {
|
||||
needSave = true
|
||||
user.emailReal = user.email
|
||||
}
|
||||
if (!user.verified || !user.emailReal) {
|
||||
if (needSave) {
|
||||
await user.save()
|
||||
}
|
||||
return { email: user.email, verified: 1 }
|
||||
|
@ -78,6 +78,11 @@ export class PayRecordClass extends BaseModule {
|
||||
@prop()
|
||||
public txHash?: string
|
||||
|
||||
@prop()
|
||||
public gameAccountId: string
|
||||
@prop()
|
||||
public gameOrderId: string
|
||||
|
||||
public static async findByRecordId(this: ReturnModelType<typeof PayRecordClass>, outOrderId: string) {
|
||||
return this.findOne({ outOrderId }).exec()
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ const DEFAULT_MSG_DATA: IMailData = {
|
||||
to: '',
|
||||
subject: 'Please verify your email address',
|
||||
}
|
||||
const MAIL_SVR = 'http://127.0.0.1:3087'
|
||||
const MAIL_SVR = process.env.EMAIL_SERVER
|
||||
|
||||
@singleton
|
||||
export class EmailSvr {
|
||||
|
28
src/service/game.svr.ts
Normal file
28
src/service/game.svr.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import axios from 'axios'
|
||||
import { PayRecordClass } from 'modules/PayRecord'
|
||||
import { DocumentType } from '@typegoose/typegoose'
|
||||
import { hmacsha256 } from 'utils/security.util'
|
||||
|
||||
export async function reportPayResult(data: DocumentType<PayRecordClass>) {
|
||||
let repData = {
|
||||
account_id: data.gameAccountId,
|
||||
order_id: data.gameOrderId,
|
||||
status: data.status,
|
||||
id: data.id,
|
||||
txhash: data.txHash,
|
||||
}
|
||||
let signStr = Object.keys(repData)
|
||||
.sort()
|
||||
.map(key => `${key}=${encodeURIComponent(repData[key])}`)
|
||||
.join('&')
|
||||
const sign = hmacsha256(signStr, process.env.HASH_SALT)
|
||||
let url = `${process.env.GAME_PAY_CB_URL}&${signStr}&sign=${sign}`
|
||||
let reqConfig: any = {
|
||||
method: 'get',
|
||||
url,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}
|
||||
return axios(reqConfig)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user