Browse Source

支付调用方法

master v0.5.1
guzeng 3 years ago
parent
commit
357bf1c377
2 changed files with 78 additions and 0 deletions
  1. +53
    -0
      payed.go
  2. +25
    -0
      payed_test.go

+ 53
- 0
payed.go View File

@ -0,0 +1,53 @@
package orderrpcv2
import (
"encoding/json"
"errors"
)
func Payed(dbname, platform string, data map[string]interface{}, url ...string) (*OrderCancelRes, error) {
if dbname == "" || len(data) < 1 {
return nil, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return nil, err
}
defer conn.Close()
data["dbname"] = dbname
data["platform"] = platform
req, err := SetReqData(data)
if err != nil {
return nil, err
}
res := &Response{}
err = conn.Payed(req, res)
if err != nil {
return nil, err
}
res_data_de, err := GetResData(res)
if err != nil {
return nil, err
}
if res_data_de == "" {
return nil, nil
}
var res_arr OrderCancelRes
err = json.Unmarshal([]byte(res_data_de), &res_arr)
if err != nil {
return nil, err
}
return &res_arr, nil
}

+ 25
- 0
payed_test.go View File

@ -0,0 +1,25 @@
package orderrpcv2
import (
"testing"
)
func Test_Payed(t *testing.T) {
payData := map[string]interface{}{
"pay_type": "wechat",
"pay_method": "jsapi",
"order_sn": "2163040248896658",
"payment_sn": "ddddd",
"payer_total": 17.66,
"total": 33.33, //单位转为元
"user_openid": "adfawrkepoieirpwoer",
"user_id": "55",
"success_time": "2021-10-12 10:20:30",
}
ret, err := Payed("shop_v2", "miniapp", payData)
t.Log(ret)
t.Log(err)
}

Loading…
Cancel
Save