93 lines
3.3 KiB
Go
93 lines
3.3 KiB
Go
|
package controller
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"encoding/xml"
|
||
|
"fmt"
|
||
|
"github.com/codinl/go-logger"
|
||
|
"mh-server/lib/wxpay"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestPushWXPayNoticeTest(t *testing.T) {
|
||
|
PushWXPayNoticeTest()
|
||
|
}
|
||
|
|
||
|
func PushWXPayNoticeTest() {
|
||
|
// body := []byte(` <xml><appid><![CDATA[wx806c079463b5b56c]]></appid>
|
||
|
//<attach><![CDATA[member_pay]]></attach>
|
||
|
//<bank_type><![CDATA[OTHERS]]></bank_type>
|
||
|
//<cash_fee><![CDATA[69900]]></cash_fee>
|
||
|
//<device_info><![CDATA[WEB]]></device_info>
|
||
|
//<fee_type><![CDATA[CNY]]></fee_type>
|
||
|
//<is_subscribe><![CDATA[N]]></is_subscribe>
|
||
|
//<mch_id><![CDATA[1609877389]]></mch_id>
|
||
|
//<nonce_str><![CDATA[3lQ34r7u3GFcHU5Tk3tjM2o2Gu7Jc8gE]]></nonce_str>
|
||
|
//<openid><![CDATA[ohuHh4sLeBcMR-C7rZsZOexMTuds]]></openid>
|
||
|
//<out_trade_no><![CDATA[7729C9C324]]></out_trade_no>
|
||
|
//<result_code><![CDATA[SUCCESS]]></result_code>
|
||
|
//<return_code><![CDATA[SUCCESS]]></return_code>
|
||
|
//<sign><![CDATA[A31D026246DF11B147A8D9FC5234C389]]></sign>
|
||
|
//<time_end><![CDATA[20220527205519]]></time_end>
|
||
|
//<total_fee>69900</total_fee>
|
||
|
//<trade_type><![CDATA[JSAPI]]></trade_type>
|
||
|
//<transaction_id><![CDATA[4200001516202205272284493470]]></transaction_id>
|
||
|
//</xml>`)
|
||
|
body := []byte(`<xml>
|
||
|
<appid><![CDATA[wx806c079463b5b56c]]></appid>
|
||
|
<attach><![CDATA[member_pay]]></attach>
|
||
|
<bank_type><![CDATA[WHZB_DEBIT]]></bank_type>
|
||
|
<cash_fee><![CDATA[63900]]></cash_fee>
|
||
|
<coupon_count><![CDATA[3]]></coupon_count>
|
||
|
<coupon_fee>6000</coupon_fee>
|
||
|
<coupon_fee_0><![CDATA[2000]]></coupon_fee_0>
|
||
|
<coupon_fee_1><![CDATA[2000]]></coupon_fee_1>
|
||
|
<coupon_fee_2><![CDATA[2000]]></coupon_fee_2>
|
||
|
<coupon_id_0><![CDATA[34002152204]]></coupon_id_0>
|
||
|
<coupon_id_1><![CDATA[34003509554]]></coupon_id_1>
|
||
|
<coupon_id_2><![CDATA[34002433276]]></coupon_id_2>
|
||
|
<device_info><![CDATA[WEB]]></device_info>
|
||
|
<fee_type><![CDATA[CNY]]></fee_type>
|
||
|
<is_subscribe><![CDATA[N]]></is_subscribe>
|
||
|
<mch_id><![CDATA[1609877389]]></mch_id>
|
||
|
<nonce_str><![CDATA[Q4POvEGK7hTPX0hy54H2mn13fG4m8Nm7]]></nonce_str>
|
||
|
<openid><![CDATA[ohuHh4jYz8Tad6kYZ8P_jNNNCI7s]]></openid>
|
||
|
<out_trade_no><![CDATA[772A907CA8]]></out_trade_no>
|
||
|
<result_code><![CDATA[SUCCESS]]></result_code>
|
||
|
<return_code><![CDATA[SUCCESS]]></return_code>
|
||
|
<sign><![CDATA[3ABCA7885BBE8658E76D384FE55AFDDE]]></sign>
|
||
|
<time_end><![CDATA[20220527214915]]></time_end>
|
||
|
<total_fee>69900</total_fee>
|
||
|
<trade_type><![CDATA[JSAPI]]></trade_type>
|
||
|
<transaction_id><![CDATA[4200001522202205275372221444]]></transaction_id>
|
||
|
</xml>`)
|
||
|
var notifyInfo wxpay.WechatNotifyInfo
|
||
|
err := xml.Unmarshal(body, ¬ifyInfo)
|
||
|
if err != nil {
|
||
|
logger.Error(err)
|
||
|
}
|
||
|
//ret := WXPayNoticeResp{
|
||
|
// ReturnCode: "FAIL",
|
||
|
//}
|
||
|
|
||
|
//fmt.Println("notifyInfo:", notifyInfo)
|
||
|
//fmt.Printf("notifyInfo:%#v", notifyInfo)
|
||
|
notifyInfoJson, _ := json.Marshal(¬ifyInfo)
|
||
|
|
||
|
fmt.Println("notifyInfoJson:", string(notifyInfoJson))
|
||
|
//correctSign, err := PayCallBackHandle(notifyInfo, config.AppConfig.WxMchSecret)
|
||
|
correctSign, err := PayCallBackHandle(notifyInfo, "DeovoMingHuiRengTianTang45675456")
|
||
|
if err != nil {
|
||
|
logger.Error("PushWXPayNotice sign create fail")
|
||
|
return
|
||
|
}
|
||
|
if notifyInfo.Sign != correctSign {
|
||
|
fmt.Println("Sign-----:", notifyInfo.Sign)
|
||
|
fmt.Println("correctSign:", correctSign)
|
||
|
logger.Error("PushWXPayNotice sign verification fail")
|
||
|
return
|
||
|
}
|
||
|
fmt.Println("Sign:", notifyInfo.Sign)
|
||
|
fmt.Println("correctSign:", correctSign)
|
||
|
}
|