Commit fbce7a23 authored by wangp's avatar wangp

update

parent 40a19fed
...@@ -6,11 +6,14 @@ package base ...@@ -6,11 +6,14 @@ package base
const ( const (
// Success 请求成功 // Success 请求成功
Success = 1000 //Success = 1000
Success = 0
// ServerError 服务器错误 // ServerError 服务器错误
ServerError = 1100 //ServerError = 1100
ServerError = 9
// Warning 警告 // Warning 警告
Warning = 1200 //Warning = 1200
Warning = 1
// FailedToObtainVerificationCode 验证码获取失败 // FailedToObtainVerificationCode 验证码获取失败
//FailedToObtainVerificationCode = 1001 //FailedToObtainVerificationCode = 1001
...@@ -19,7 +22,8 @@ const ( ...@@ -19,7 +22,8 @@ const (
// VerificationCodeError 验证码错误 // VerificationCodeError 验证码错误
//VerificationCodeError = 1003 //VerificationCodeError = 1003
// AuthorizationEmpty token为空 // AuthorizationEmpty token为空
AuthorizationEmpty = 1004 //AuthorizationEmpty = 1004
AuthorizationEmpty = 4
// ThisAccountDoesNotHavePermission 此账号没有权限 // ThisAccountDoesNotHavePermission 此账号没有权限
//ThisAccountDoesNotHavePermission = 1005 //ThisAccountDoesNotHavePermission = 1005
// ParameterValidationFailed 参数效验失败 // ParameterValidationFailed 参数效验失败
......
...@@ -15,35 +15,61 @@ import ( ...@@ -15,35 +15,61 @@ import (
*/ */
// ResponseData 统一返回数据 // ResponseData 统一返回数据
//type ResponseData struct {
// Code int `json:"code"`
// Msg interface{} `json:"msg"`
// Data interface{} `json:"data,omitempty"`
//}
type ResponseData struct { type ResponseData struct {
Code int `json:"code"` Status int `json:"Status"`
Msg interface{} `json:"msg"` Message interface{} `json:"Message"`
Data interface{} `json:"data,omitempty"` Data interface{} `json:"Data,omitempty"`
} }
// ResponseErrorWithMsg 返回错误 // ResponseErrorWithMsg 返回错误
//func ResponseErrorWithMsg(c *gin.Context, code int) {
// c.JSON(http.StatusOK, &ResponseData{
// Code: code,
// Msg: InternationalizedMsg(c, code),
// Data: nil,
// })
//}
func ResponseErrorWithMsg(c *gin.Context, code int) { func ResponseErrorWithMsg(c *gin.Context, code int) {
c.JSON(http.StatusOK, &ResponseData{ c.JSON(http.StatusOK, &ResponseData{
Code: code, Status: code,
Msg: InternationalizedMsg(c, code), Message: InternationalizedMsg(c, code),
Data: nil, Data: nil,
}) })
} }
// ResponseSuccess 返回正确 // ResponseSuccess 返回正确
//func ResponseSuccess(c *gin.Context, data interface{}) {
// c.JSON(http.StatusOK, &ResponseData{
// Code: Success,
// Msg: InternationalizedMsg(c, Success),
// Data: data,
// })
//}
func ResponseSuccess(c *gin.Context, data interface{}) { func ResponseSuccess(c *gin.Context, data interface{}) {
c.JSON(http.StatusOK, &ResponseData{ c.JSON(http.StatusOK, &ResponseData{
Code: Success, Status: Success,
Msg: InternationalizedMsg(c, Success), Message: InternationalizedMsg(c, Success),
Data: data, Data: data,
}) })
} }
// ResponseErrorMsg 直接返回msg // ResponseErrorMsg 直接返回msg
//func ResponseErrorMsg(c *gin.Context, msg string) {
// c.JSON(http.StatusOK, &ResponseData{
// Code: Warning,
// Msg: msg,
// Data: nil,
// })
//}
func ResponseErrorMsg(c *gin.Context, msg string) { func ResponseErrorMsg(c *gin.Context, msg string) {
c.JSON(http.StatusOK, &ResponseData{ c.JSON(http.StatusOK, &ResponseData{
Code: Warning, Status: Warning,
Msg: msg, Message: msg,
Data: nil, Data: nil,
}) })
} }
\ No newline at end of file
...@@ -18,16 +18,6 @@ import ( ...@@ -18,16 +18,6 @@ import (
"time" "time"
) )
func RandomString(n int) string {
var letters = []byte("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
result := make([]byte, n)
rand2.Seed(time.Now().Unix())
for i := range result {
result[i] = letters[rand2.Intn(len(letters))]
}
return string(result)
}
// 拉卡拉支付 // 拉卡拉支付
func UnifiedOrder(input *models.PlaceAnOrderParamInput) (interface{}, error) { func UnifiedOrder(input *models.PlaceAnOrderParamInput) (interface{}, error) {
...@@ -41,6 +31,9 @@ func UnifiedOrder(input *models.PlaceAnOrderParamInput) (interface{}, error) { ...@@ -41,6 +31,9 @@ func UnifiedOrder(input *models.PlaceAnOrderParamInput) (interface{}, error) {
//} //}
//rtn := make(map[string]string) //rtn := make(map[string]string)
fmt.Println("接口输入参数")
fmt.Println(input)
data := make(map[string]interface{}) data := make(map[string]interface{})
data["req_time"] = "20220714160009" data["req_time"] = "20220714160009"
data["version"] = "3.0" data["version"] = "3.0"
...@@ -64,6 +57,9 @@ func UnifiedOrder(input *models.PlaceAnOrderParamInput) (interface{}, error) { ...@@ -64,6 +57,9 @@ func UnifiedOrder(input *models.PlaceAnOrderParamInput) (interface{}, error) {
// "extend_info": "自动化测试", // "extend_info": "自动化测试",
// "callback_url": "" // "callback_url": ""
input.NoticeURL = "https://test.pet-dbc.cn/uni/api/repayment/PayCallBack"
input.ReturnURL = "https://test.pet-dbc.cn"
data2 := make(map[string]interface{}) data2 := make(map[string]interface{})
//data2["out_trade_no"] = "FD660E1FAA3A4470933CDEDAE1EC1DUU" //data2["out_trade_no"] = "FD660E1FAA3A4470933CDEDAE1EC1DUU"
data2["out_trade_no"] = RandomString(32) data2["out_trade_no"] = RandomString(32)
...@@ -392,7 +388,6 @@ func lakala_post(url string, data_json []byte) (error, string) { ...@@ -392,7 +388,6 @@ func lakala_post(url string, data_json []byte) (error, string) {
temp2, _ := temp["resp_data"].(map[string]interface{}) temp2, _ := temp["resp_data"].(map[string]interface{})
if temp2["counter_url"]=="" { if temp2["counter_url"]=="" {
fmt.Println(temp2)
return errors.New("拉卡拉返回值「counter_url」为空错误"), "" return errors.New("拉卡拉返回值「counter_url」为空错误"), ""
} }
...@@ -497,3 +492,14 @@ func genPriKey(privateKey []byte, privateKeyType int64) (*rsa.PrivateKey, error) ...@@ -497,3 +492,14 @@ func genPriKey(privateKey []byte, privateKeyType int64) (*rsa.PrivateKey, error)
} }
return priKey, nil return priKey, nil
} }
//生产随机字符串
func RandomString(n int) string {
var letters = []byte("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
result := make([]byte, n)
rand2.Seed(time.Now().Unix())
for i := range result {
result[i] = letters[rand2.Intn(len(letters))]
}
return string(result)
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment