调整AccessPlatformAPIWithRetry中的调试输出信息
+wxpayapi.CloseOrder
This commit is contained in:
@@ -153,6 +153,11 @@ type CreateOrderParam struct {
|
||||
SceneInfo string `json:"scene_info,omitempty" xml:"scene_info,omitempty"`
|
||||
}
|
||||
|
||||
type CloseOrderParam struct {
|
||||
RequestBase
|
||||
OutTradeNo string `json:"out_trade_no" xml:"out_trade_no"`
|
||||
}
|
||||
|
||||
type CreateOrderResult struct {
|
||||
ReturnCode string `json:"return_code" xml:"return_code"`
|
||||
ReturnMsg string `json:"return_msg" xml:"return_msg"`
|
||||
@@ -163,6 +168,7 @@ type CreateOrderResult struct {
|
||||
NonceStr string `json:"nonce_str" xml:"nonce_str"`
|
||||
Sign string `json:"sign" xml:"sign"`
|
||||
ResultCode string `json:"result_code" xml:"result_code"`
|
||||
ResultMsg string `json:"result_msg" xml:"result_msg"`
|
||||
ErrCode string `json:"err_code,omitempty" xml:"err_code,omitempty"`
|
||||
ErrCodeDes string `json:"err_code_des,omitempty" xml:"err_code_des,omitempty"`
|
||||
|
||||
@@ -195,6 +201,7 @@ type PayRefundResult struct {
|
||||
NonceStr string `json:"nonce_str" xml:"nonce_str"`
|
||||
Sign string `json:"sign" xml:"sign"`
|
||||
ResultCode string `json:"result_code" xml:"result_code"`
|
||||
ResultMsg string `json:"result_msg" xml:"result_msg"`
|
||||
ErrCode string `json:"err_code,omitempty" xml:"err_code,omitempty"`
|
||||
ErrCodeDes string `json:"err_code_des,omitempty" xml:"err_code_des,omitempty"`
|
||||
|
||||
@@ -315,12 +322,19 @@ func (a *API) AccessAPI(action string, requestParam IRequestBase) (retVal map[st
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
func (a *API) checkResultAsMap(xmlStr string) (result map[string]interface{}, errLevel string, err error) {
|
||||
func (a *API) parseXmlStrAsMap(xmlStr string) (result map[string]interface{}, errLevel string, err error) {
|
||||
mv, err := mxj.NewMapXml([]byte(xmlStr))
|
||||
if err != nil {
|
||||
errLevel = platformapi.ErrLevelGeneralFail
|
||||
} else {
|
||||
result = mv["xml"].(map[string]interface{})
|
||||
}
|
||||
return result, errLevel, err
|
||||
}
|
||||
|
||||
func (a *API) checkResultAsMap(xmlStr string) (result map[string]interface{}, errLevel string, err error) {
|
||||
result, errLevel, err = a.parseXmlStrAsMap(xmlStr)
|
||||
if err == nil {
|
||||
returnCode := utils.Interface2String(result["return_code"])
|
||||
if returnCode != ResponseCodeSuccess {
|
||||
errLevel = platformapi.ErrLevelGeneralFail
|
||||
@@ -344,6 +358,20 @@ func PayTime2Time(str string) (t time.Time) {
|
||||
return t
|
||||
}
|
||||
|
||||
func (a *API) mapData2Err(mapData map[string]interface{}) (err error) {
|
||||
if resultCode := utils.Interface2String(mapData["result_code"]); resultCode != ResponseCodeSuccess {
|
||||
err = utils.NewErrorCode(utils.Interface2String(mapData["err_code_des"]), utils.Interface2String(mapData["err_code"]))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) translateResult(mapData map[string]interface{}, dataPtr interface{}) (err error) {
|
||||
if err = a.mapData2Err(mapData); err == nil && dataPtr != nil {
|
||||
err = utils.Map2StructByJson(mapData, dataPtr, false)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) OrderQuery(transactionID, outTradeNo string) (orderInfo *OrderInfo, err error) {
|
||||
param := &OrderQueryParam{
|
||||
TransactionID: transactionID,
|
||||
@@ -351,7 +379,7 @@ func (a *API) OrderQuery(transactionID, outTradeNo string) (orderInfo *OrderInfo
|
||||
}
|
||||
retVal, err := a.AccessAPI("pay/orderquery", param)
|
||||
if err == nil {
|
||||
err = utils.Map2StructByJson(retVal, &orderInfo, false)
|
||||
err = a.translateResult(retVal, &orderInfo)
|
||||
}
|
||||
return orderInfo, err
|
||||
}
|
||||
@@ -359,18 +387,32 @@ func (a *API) OrderQuery(transactionID, outTradeNo string) (orderInfo *OrderInfo
|
||||
func (a *API) CreateUnifiedOrder(param *CreateOrderParam) (createOrderResult *CreateOrderResult, err error) {
|
||||
retVal, err := a.AccessAPI("pay/unifiedorder", param)
|
||||
if err == nil {
|
||||
err = utils.Map2StructByJson(retVal, &createOrderResult, false)
|
||||
err = a.translateResult(retVal, &createOrderResult)
|
||||
}
|
||||
return createOrderResult, err
|
||||
}
|
||||
|
||||
// 关闭订单
|
||||
// https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_3
|
||||
// 注意:订单生成后不能马上调用关单接口,最短调用时间间隔为5分钟。
|
||||
// 此函数好像可以重复操作,且关闭一个不存在的订单也不会报错的样
|
||||
func (a *API) CloseOrder(outTradeNo string) (err error) {
|
||||
retVal, err := a.AccessAPI("pay/closeorder", &CloseOrderParam{
|
||||
OutTradeNo: outTradeNo,
|
||||
})
|
||||
if err == nil {
|
||||
err = a.translateResult(retVal, nil)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) PayRefund(param *PayRefundParam) (refundResult *PayRefundResult, err error) {
|
||||
if a.client.Transport == nil {
|
||||
return nil, fmt.Errorf("没有配置证书,不能退款")
|
||||
}
|
||||
retVal, err := a.AccessAPI("secapi/pay/refund", param)
|
||||
if err == nil {
|
||||
err = utils.Map2StructByJson(retVal, &refundResult, false)
|
||||
err = a.translateResult(retVal, &refundResult)
|
||||
}
|
||||
return refundResult, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user