|
- package fb_pay
-
- import (
- zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils"
- "errors"
- "fmt"
- "strings"
- )
-
- func GetUnificationByVendorSn(vendorSn string) *RequestParameters {
- var rp RequestParameters
- rp.VendorSn = vendorSn
- rp.Method = Unification
- return &rp
- }
-
- func GetOrderQrcodeByVendorSn(vendorSn string) *RequestParameters {
- var rp RequestParameters
- rp.VendorSn = vendorSn
- rp.Method = OrderQrcode
- return &rp
- }
-
- func GetAggregateCodeByVendorSn(vendorSn string) *RequestParameters {
- var rp RequestParameters
- rp.VendorSn = vendorSn
- rp.Method = AggregateCode
- return &rp
- }
-
- func GetRequestParametersByVendorSn(vendorSn string) *RequestParameters {
- var rp RequestParameters
- rp.VendorSn = vendorSn
- return &rp
- }
-
- func GetUnificationByAppId(appId string) *RequestParameters {
- var rp RequestParameters
- rp.AppId = appId
- rp.Method = Unification
- return &rp
- }
-
- func GetOrderQrcodeByAppId(appId string) *RequestParameters {
- var rp RequestParameters
- rp.AppId = appId
- rp.Method = OrderQrcode
- return &rp
- }
-
- func GetAggregateCodeByAppId(appId string) *RequestParameters {
- var rp RequestParameters
- rp.AppId = appId
- rp.Method = AggregateCode
- return &rp
- }
-
- func GetRequestParametersByAppId(appId string) *RequestParameters {
- var rp RequestParameters
- rp.AppId = appId
- return &rp
- }
-
- func (bp *BaseParameters) SetBizContent(param interface{}) {
- fmt.Println("参数:", zhios_pay_utils.SerializeStr(param))
- bp.BizContent = zhios_pay_utils.SerializeStr(param)
- }
-
- func (bp *BaseParameters) GetSign(appSecret string) string {
- struct2Map := make(map[string]string)
- zhios_pay_utils.Unserialize(zhios_pay_utils.Serialize(bp), &struct2Map)
- needSignStr := zhios_pay_utils.JoinStringsInASCII(struct2Map, "&", "=", false, false)
- needSignStr = needSignStr + appSecret
- return strings.ToUpper(zhios_pay_utils.Md5(needSignStr))
- }
-
- func (rp *RequestParameters) SetSign(appSecret string) {
- rp.Sign = rp.BaseParameters.GetSign(appSecret)
- }
-
- func (rp *RequestParameters) Send(prd bool) (string, error) {
- if rp.Sign == "" {
- return "", errors.New("请进行签名")
- }
- param := zhios_pay_utils.Struct2Map(rp)
- for key, value := range param {
- if value == "" {
- delete(param, key)
- }
- }
- url := TestUrl
- if prd {
- url = PrdUrl
- }
- headers := map[string]string{
- "Content-Type": ReqHeader,
- }
- zhios_pay_utils.CurlDebug = true
- res, err := zhios_pay_utils.CurlPost(url, zhios_pay_utils.SerializeStr(param), headers)
- if err != nil {
- return "", err
- }
- fmt.Println(string(res))
- return string(res), nil
- }
|