|
|
@@ -224,6 +224,57 @@ export class WeixinService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async pay2(openid: string) {
|
|
|
+ try {
|
|
|
+ let reqObj = {
|
|
|
+ appid: this.weixinConfiguration.appId,
|
|
|
+ mch_id: this.weixinConfiguration.mchId,
|
|
|
+ nonce_str: Kits.generateStr(), //生成随机字符串
|
|
|
+ body: 'IJPay 让支付触手可及',
|
|
|
+ attach: 'TNWX 微信系开发脚手架',
|
|
|
+ out_trade_no: Kits.generateStr(),
|
|
|
+ total_fee: 666,
|
|
|
+ spbill_create_ip: '192.168.101.1',
|
|
|
+ notify_url: 'https://chillgpt.raexmeta.com/weixin/notify',
|
|
|
+ trade_type: WX_TRADE_TYPE.JSAPI,
|
|
|
+ sign_type: SIGN_TYPE.SIGN_TYPE_HMACSHA256,
|
|
|
+ openid
|
|
|
+ }
|
|
|
+ let xml = await Kits.generateSignedXml(
|
|
|
+ reqObj,
|
|
|
+ this.weixinConfiguration.mchKey,
|
|
|
+ SIGN_TYPE.SIGN_TYPE_HMACSHA256
|
|
|
+ )
|
|
|
+
|
|
|
+ let data = await HttpKit.getHttpDelegate.httpPost(WX_DOMAIN.CHINA.concat(WX_API_TYPE.UNIFIED_ORDER), xml)
|
|
|
+ const res = await Kits.xml2obj(data)
|
|
|
+ console.log(res)
|
|
|
+
|
|
|
+ const signObj = {
|
|
|
+ appId: this.weixinConfiguration.appId,
|
|
|
+ timeStamp: new Date().getTime().toString(),
|
|
|
+ nonceStr: Kits.generateStr(),
|
|
|
+ package: 'prepay_id=' + res.prepay_id,
|
|
|
+ signType: 'HMAC-SHA256'
|
|
|
+ }
|
|
|
+ const signStr = Object.keys(signObj)
|
|
|
+ .sort()
|
|
|
+ .map((key) => {
|
|
|
+ return `${key}=${signObj[key]}`
|
|
|
+ })
|
|
|
+ .join()
|
|
|
+ console.log(signStr)
|
|
|
+ const paySign = Kits.hmacsha256(signStr, this.privateKey.toString())
|
|
|
+ console.log(paySign)
|
|
|
+ return {
|
|
|
+ ...signObj,
|
|
|
+ paySign
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async getCert() {
|
|
|
try {
|
|
|
let result = await PayKit.exeGet(
|