增加一些日志
This commit is contained in:
parent
8fb2500443
commit
f38f5f5fd1
@ -84,8 +84,8 @@ class AlchemyController extends BaseController {
|
|||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
reportPayResult(record)
|
reportPayResult(record)
|
||||||
})
|
})
|
||||||
|
throw new ZError(payRes.returnCode, payRes.returnMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
return { url: payRes.data.payUrl }
|
return { url: payRes.data.payUrl }
|
||||||
}
|
}
|
||||||
@router('post /pay/alchemy/buypage')
|
@router('post /pay/alchemy/buypage')
|
||||||
|
@ -2,13 +2,14 @@ import logger from 'logger/logger'
|
|||||||
import BaseController, { ROLE_ANON } from 'common/base.controller'
|
import BaseController, { ROLE_ANON } from 'common/base.controller'
|
||||||
import { ZError } from 'common/ZError'
|
import { ZError } from 'common/ZError'
|
||||||
import { role, router } from 'decorators/router'
|
import { role, router } from 'decorators/router'
|
||||||
import { checkPayResultSign, checkSimpleSign } from 'service/alchemy.svr'
|
import { checkPayResultSign, checkSha1Sign, checkSimpleSign } from 'service/alchemy.svr'
|
||||||
import { PayRecord, PayStatus } from 'modules/PayRecord'
|
import { PayRecord, PayStatus } from 'modules/PayRecord'
|
||||||
import { TransferQueue } from 'queue/transfer.queue'
|
import { TransferQueue } from 'queue/transfer.queue'
|
||||||
import { TransferRecord } from 'modules/TransferRecord'
|
import { TransferRecord } from 'modules/TransferRecord'
|
||||||
import { reportPayResult } from 'service/game.svr'
|
import { reportPayResult } from 'service/game.svr'
|
||||||
|
|
||||||
let errorRes = function (msg: string) {
|
let errorRes = function (msg: string) {
|
||||||
|
logger.info(`error res: ${msg}`)
|
||||||
return {
|
return {
|
||||||
direct: 1,
|
direct: 1,
|
||||||
data: null,
|
data: null,
|
||||||
@ -25,6 +26,7 @@ class AlchemyOutController extends BaseController {
|
|||||||
@router('post /pay/out/alchemy/buycb')
|
@router('post /pay/out/alchemy/buycb')
|
||||||
async alchemyCallback(req, res) {
|
async alchemyCallback(req, res) {
|
||||||
let { orderNo, status, crypto, network, merchantOrderNo } = req.params
|
let { orderNo, status, crypto, network, merchantOrderNo } = req.params
|
||||||
|
logger.info(`alchemy callback: ${orderNo}, ${status}, ${crypto}, ${network}, ${merchantOrderNo}`)
|
||||||
if (!merchantOrderNo) {
|
if (!merchantOrderNo) {
|
||||||
logger.info(`alchemy callback merchantOrderNo not found`)
|
logger.info(`alchemy callback merchantOrderNo not found`)
|
||||||
throw new ZError(11, 'alchemy callback merchantOrderNo not found')
|
throw new ZError(11, 'alchemy callback merchantOrderNo not found')
|
||||||
@ -75,7 +77,9 @@ class AlchemyOutController extends BaseController {
|
|||||||
@router('get /pay/out/alchemy/queryprice')
|
@router('get /pay/out/alchemy/queryprice')
|
||||||
async queryToken(req, res) {
|
async queryToken(req, res) {
|
||||||
const { crypto } = req.params
|
const { crypto } = req.params
|
||||||
|
logger.info(`alchemy query price: ${crypto}`)
|
||||||
let { appId, appid, timestamp, sign } = req.headers
|
let { appId, appid, timestamp, sign } = req.headers
|
||||||
|
logger.info(`alchemy query price headers: ${appid}, ${timestamp}, ${sign}`)
|
||||||
if (!crypto) {
|
if (!crypto) {
|
||||||
return errorRes('params mismatch')
|
return errorRes('params mismatch')
|
||||||
}
|
}
|
||||||
@ -83,7 +87,7 @@ class AlchemyOutController extends BaseController {
|
|||||||
if (!appId || !timestamp || !sign) {
|
if (!appId || !timestamp || !sign) {
|
||||||
return errorRes('headers mismatch')
|
return errorRes('headers mismatch')
|
||||||
}
|
}
|
||||||
if (!checkSimpleSign(req.headers, { crypto })) {
|
if (!checkSha1Sign(req.headers)) {
|
||||||
return errorRes('sign error')
|
return errorRes('sign error')
|
||||||
}
|
}
|
||||||
let result = {
|
let result = {
|
||||||
@ -92,7 +96,7 @@ class AlchemyOutController extends BaseController {
|
|||||||
price: '1.0',
|
price: '1.0',
|
||||||
networkList: [
|
networkList: [
|
||||||
{
|
{
|
||||||
network: 'ETH',
|
network: 'AGOR',
|
||||||
networkFee: '0.037',
|
networkFee: '0.037',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -106,22 +110,25 @@ class AlchemyOutController extends BaseController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 通知商户打币
|
* 通知商户打币
|
||||||
* TODO::test
|
|
||||||
*/
|
*/
|
||||||
@role(ROLE_ANON)
|
@role(ROLE_ANON)
|
||||||
@router('post /pay/out/alchemy/distribute')
|
@router('post /pay/out/alchemy/distribute')
|
||||||
async distributeToken(req, res) {
|
async distributeToken(req, res) {
|
||||||
const { orderNo, crypto, network, address, cryptoAmount, cryptoPrice, usdtAmount } = req.params
|
const { orderNo, crypto, network, address, cryptoAmount, cryptoPrice, usdtAmount } = req.params
|
||||||
|
logger.info(
|
||||||
|
`alchemy distributeToken: orderNo: ${orderNo}, crypto: ${crypto}, network: ${network}, address: ${address}, cryptoAmount: ${cryptoAmount}, cryptoPrice: ${cryptoPrice}, usdtAmount: ${usdtAmount}`,
|
||||||
|
)
|
||||||
let { appId, appid, timestamp, sign } = req.headers
|
let { appId, appid, timestamp, sign } = req.headers
|
||||||
|
logger.info(`alchemy distributeToken: appId: ${appId || appid}, timestamp: ${timestamp}, sign: ${sign}`)
|
||||||
if (!orderNo || !crypto || !network || !address || !cryptoAmount || !cryptoPrice || !usdtAmount) {
|
if (!orderNo || !crypto || !network || !address || !cryptoAmount || !cryptoPrice || !usdtAmount) {
|
||||||
return errorRes('params mismatch')
|
return errorRes('params mismatch')
|
||||||
}
|
}
|
||||||
appId = appId || appid
|
appId = appId || appid
|
||||||
if (!appId || !timestamp || !sign) {
|
if (!timestamp || !sign) {
|
||||||
return errorRes('headers mismatch')
|
return errorRes('headers mismatch')
|
||||||
}
|
}
|
||||||
let signData = { orderNo, crypto, network, address, cryptoAmount, cryptoPrice, usdtAmount }
|
// let signData = { orderNo, crypto, network, address, cryptoAmount, cryptoPrice, usdtAmount }
|
||||||
if (!checkSimpleSign(req.headers, signData)) {
|
if (!checkSha1Sign(req.headers)) {
|
||||||
return errorRes('sign error')
|
return errorRes('sign error')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ export enum PlatEnum {
|
|||||||
TWITTER = 4,
|
TWITTER = 4,
|
||||||
TELEGRAM = 5,
|
TELEGRAM = 5,
|
||||||
EMAIL = 6,
|
EMAIL = 6,
|
||||||
|
DISCORD = 7,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,6 +2,7 @@ import axios from 'axios'
|
|||||||
import { hmacsha256, sha1 } from 'utils/security.util'
|
import { hmacsha256, sha1 } from 'utils/security.util'
|
||||||
import crypto from 'crypto'
|
import crypto from 'crypto'
|
||||||
import { generateKVStr } from 'utils/net.util'
|
import { generateKVStr } from 'utils/net.util'
|
||||||
|
import logger from 'logger/logger'
|
||||||
|
|
||||||
export function createSimpleSign(data: any) {
|
export function createSimpleSign(data: any) {
|
||||||
let timestamp = Date.now()
|
let timestamp = Date.now()
|
||||||
@ -40,7 +41,7 @@ export function createSha1Sign() {
|
|||||||
*/
|
*/
|
||||||
export function checkPayResultSign(data: any) {
|
export function checkPayResultSign(data: any) {
|
||||||
const { appId, orderNo, crypto, network, address, signature } = data
|
const { appId, orderNo, crypto, network, address, signature } = data
|
||||||
const sign = hmacsha256(appId + orderNo + crypto + network + address, process.env.ALCHEMY_APP_SECRET)
|
const sign = sha1(appId + process.env.ALCHEMY_APP_SECRET + appId + orderNo + crypto + network + address)
|
||||||
return sign === signature
|
return sign === signature
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,6 +56,7 @@ export function checkSimpleSign(headers: any, data: any) {
|
|||||||
.map(key => `${key}=${signData[key]}`)
|
.map(key => `${key}=${signData[key]}`)
|
||||||
.join('&')
|
.join('&')
|
||||||
const expectedSign = hmacsha256(signStr, process.env.ALCHEMY_APP_SECRET)
|
const expectedSign = hmacsha256(signStr, process.env.ALCHEMY_APP_SECRET)
|
||||||
|
logger.info('compare sign: ', sign, expectedSign)
|
||||||
// const expectedSign = sha1(appIdToCheck + process.env.ALCHEMY_APP_SECRET + timestamp)
|
// const expectedSign = sha1(appIdToCheck + process.env.ALCHEMY_APP_SECRET + timestamp)
|
||||||
return sign === expectedSign
|
return sign === expectedSign
|
||||||
}
|
}
|
||||||
@ -83,6 +85,12 @@ export function createPageSign(plainText: string) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function checkSha1Sign(headers: any) {
|
||||||
|
const { appid, appId, timestamp, sign } = headers
|
||||||
|
let appIdToCheck = appId || appid || process.env.ALCHEMY_APPID
|
||||||
|
const expectedSign = sha1(appIdToCheck + process.env.ALCHEMY_APP_SECRET + timestamp)
|
||||||
|
return sign === expectedSign
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Refresh token
|
* Refresh token
|
||||||
* https://alchemycn.readme.io/docs/获取token
|
* https://alchemycn.readme.io/docs/获取token
|
||||||
|
Loading…
x
Reference in New Issue
Block a user