|
|
@ -2,6 +2,7 @@ package wechat |
|
|
|
|
|
|
|
import ( |
|
|
|
"encoding/xml" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"log" |
|
|
|
"reflect" |
|
|
@ -134,7 +135,7 @@ type ReverseReturnXml struct { |
|
|
|
* @param auth_code 付款码 |
|
|
|
*/ |
|
|
|
|
|
|
|
func MicroPay(appid, mchid, mch_key, device_info, body, out_trade_no, auth_code, total_fee string) (bool, string, PayReturnXml) { |
|
|
|
func MicroPay(appid, mchid, mch_key, device_info, body, out_trade_no, auth_code, total_fee string) (PayReturnXml, error) { |
|
|
|
|
|
|
|
log.Println("wechat micropay") |
|
|
|
|
|
|
@ -173,13 +174,13 @@ func MicroPay(appid, mchid, mch_key, device_info, body, out_trade_no, auth_code, |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
log.Println("Err:", err) |
|
|
|
return false, "微信支付失败,请检查网络", retXml |
|
|
|
return retXml, errors.New("微信支付失败,请检查网络") |
|
|
|
} |
|
|
|
|
|
|
|
err = xml.Unmarshal(ret, &retXml) |
|
|
|
if err != nil { |
|
|
|
log.Println("xml Unmarshal Err:", retXml, err) |
|
|
|
return false, "未知的支付结果", retXml |
|
|
|
return retXml, errors.New("未知的支付结果") |
|
|
|
} |
|
|
|
|
|
|
|
if retXml.ResultCode == "SUCCESS" { |
|
|
@ -193,16 +194,16 @@ func MicroPay(appid, mchid, mch_key, device_info, body, out_trade_no, auth_code, |
|
|
|
|
|
|
|
if sign != retXml.Sign { |
|
|
|
log.Println("Err:签名错误", string(ret), sign) |
|
|
|
return false, "支付结果签名错误", retXml |
|
|
|
return retXml, errors.New("支付结果签名错误") |
|
|
|
} |
|
|
|
} else { |
|
|
|
return false, retXml.ReturnMsg, retXml |
|
|
|
return retXml, errors.New(retXml.ReturnMsg) |
|
|
|
} |
|
|
|
|
|
|
|
return true, "", retXml |
|
|
|
return retXml, nil |
|
|
|
} |
|
|
|
|
|
|
|
func MicroPayQuery(appid, mchid, out_trade_no, mch_key string) (bool, string, QueryReturnXml) { |
|
|
|
func MicroPayQuery(appid, mchid, out_trade_no, mch_key string) (QueryReturnXml, error) { |
|
|
|
|
|
|
|
log.Println("wechat micropay query", out_trade_no) |
|
|
|
|
|
|
@ -228,13 +229,13 @@ func MicroPayQuery(appid, mchid, out_trade_no, mch_key string) (bool, string, Qu |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
log.Println("Err:", err) |
|
|
|
return false, "微信支付失败,请检查网络", retXml |
|
|
|
return retXml, errors.New("微信支付失败,请检查网络") |
|
|
|
} |
|
|
|
|
|
|
|
err = xml.Unmarshal(ret, &retXml) |
|
|
|
if err != nil { |
|
|
|
log.Println("xml Unmarshal Err:", retXml, err) |
|
|
|
return false, "未知的支付结果", retXml |
|
|
|
return retXml, errors.New("未知的支付结果") |
|
|
|
} |
|
|
|
|
|
|
|
if retXml.ReturnCode == "SUCCESS" { |
|
|
@ -248,19 +249,19 @@ func MicroPayQuery(appid, mchid, out_trade_no, mch_key string) (bool, string, Qu |
|
|
|
|
|
|
|
if sign != retXml.Sign { |
|
|
|
log.Println("Err:签名错误", string(ret), sign) |
|
|
|
return false, "查询支付结果签名错误", retXml |
|
|
|
return retXml, errors.New("查询支付结果签名错误") |
|
|
|
} |
|
|
|
} else { |
|
|
|
return false, retXml.ReturnMsg, retXml |
|
|
|
return retXml, errors.New(retXml.ReturnMsg) |
|
|
|
} |
|
|
|
return true, "", retXml |
|
|
|
return retXml, nil |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 撤消订单 |
|
|
|
* 2023/06/13 |
|
|
|
*/ |
|
|
|
func MicroPayReverse(appid, mchid, out_trade_no, mch_key string) (bool, string, QueryReturnXml) { |
|
|
|
func MicroPayReverse(appid, mchid, out_trade_no, mch_key string) (QueryReturnXml, error) { |
|
|
|
|
|
|
|
log.Println("wechat micropay reverse", out_trade_no) |
|
|
|
|
|
|
@ -286,13 +287,13 @@ func MicroPayReverse(appid, mchid, out_trade_no, mch_key string) (bool, string, |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
log.Println("Err:", err) |
|
|
|
return false, "撤消微信支付失败,请检查网络", retXml |
|
|
|
return retXml, errors.New("撤消微信支付失败,请检查网络") |
|
|
|
} |
|
|
|
|
|
|
|
err = xml.Unmarshal(ret, &retXml) |
|
|
|
if err != nil { |
|
|
|
log.Println("xml Unmarshal Err:", retXml, err) |
|
|
|
return false, "未知的撤消结果", retXml |
|
|
|
return retXml, errors.New("未知的撤消结果") |
|
|
|
} |
|
|
|
|
|
|
|
if retXml.ReturnCode == "SUCCESS" { |
|
|
@ -306,12 +307,13 @@ func MicroPayReverse(appid, mchid, out_trade_no, mch_key string) (bool, string, |
|
|
|
|
|
|
|
if sign != retXml.Sign { |
|
|
|
log.Println("Err:签名错误", string(ret), sign) |
|
|
|
return false, "查询支付结果签名错误", retXml |
|
|
|
return retXml, errors.New("查询支付结果签名错误") |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
return false, retXml.ReturnMsg, retXml |
|
|
|
return retXml, errors.New(retXml.ReturnMsg) |
|
|
|
} |
|
|
|
return true, "", retXml |
|
|
|
return retXml, nil |
|
|
|
} |
|
|
|
|
|
|
|
func XmlStructToMap(retXml interface{}) map[string]string { |
|
|
|