Преглед на файлове

Merge remote-tracking branch 'origin/master'

tags/v1.6.1
DengBiao преди 1 година
родител
ревизия
4d5bb35ea5
променени са 14 файла, в които са добавени 978 реда и са изтрити 7 реда
  1. +2
    -0
      go.mod
  2. +12
    -1
      lib/fb_pay/fb_pay.go
  3. +54
    -0
      lib/local_alipay/api.go
  4. +30
    -0
      lib/local_wechat/api.go
  5. +1
    -1
      lib/luso_bank/macao_luso.go
  6. +152
    -0
      md/alipay.go
  7. +5
    -4
      md/boc.go
  8. +417
    -0
      pay/alipay.go
  9. +19
    -1
      pay/pay_by_own.go
  10. +86
    -0
      test/fb_pay_test.go
  11. +33
    -0
      utils/qrcode/decodeFile.go
  12. +43
    -0
      utils/qrcode/getBase64.go
  13. +85
    -0
      utils/qrcode/saveFile.go
  14. +39
    -0
      utils/qrcode/writeWeb.go

+ 2
- 0
go.mod Целия файл

@@ -3,12 +3,14 @@ module code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git
go 1.15

require (
github.com/boombuler/barcode v1.0.1
github.com/forgoer/openssl v1.2.1
github.com/gin-gonic/gin v1.8.0
github.com/go-redis/redis v6.15.9+incompatible
github.com/go-sql-driver/mysql v1.6.0
github.com/gomodule/redigo v1.8.8
github.com/iGoogle-ink/gopay v1.5.36
github.com/makiuchi-d/gozxing v0.1.1
github.com/pkg/errors v0.9.1
github.com/shopspring/decimal v1.2.0
github.com/syyongx/php2go v0.9.7


+ 12
- 1
lib/fb_pay/fb_pay.go Целия файл

@@ -20,7 +20,18 @@ func GetOrderQrcodeByVendorSn(vendorSn string) *RequestParameters {
rp.Method = OrderQrcode
return &rp
}

func GetRefundByVendorSn(vendorSn string) *RequestParameters {
var rp RequestParameters
rp.VendorSn = vendorSn
rp.Method = Refund
return &rp
}
func GetRefundQueryByVendorSn(vendorSn string) *RequestParameters {
var rp RequestParameters
rp.VendorSn = vendorSn
rp.Method = RefundQuery
return &rp
}
func GetAggregateCodeByVendorSn(vendorSn string) *RequestParameters {
var rp RequestParameters
rp.VendorSn = vendorSn


+ 54
- 0
lib/local_alipay/api.go Целия файл

@@ -65,6 +65,60 @@ func TradeAppPay(appID, priKey, subject, orderID, amount, notiURL, RSA, PKCS str
}
return payParam, nil
}
func TradeAppPc(appID, priKey, subject, orderID, amount, notiURL, RSA, PKCS string, paySet *md.PayData) (string, error) {
//初始化支付宝客户端
// appID 是在支付宝申请的APPID
// priKey 是支付宝私钥
// subject 是支付订单的主题
// orderID 是智莺这边生成的订单id
// amount 是付费金额
// notiURL 通知地址url
// passback_params 回调通知参数

client := alipay.NewClient(appID, priKey, true)
client.DebugSwitch = gopay.DebugOn
//判断密钥的类型
rsa_type := alipay.RSA2
pkcs_type := alipay.PKCS1
if RSA == "1" {
rsa_type = alipay.RSA
}
if PKCS == "1" {
pkcs_type = alipay.PKCS8
}
if paySet.PayAliUseType == "1" {
rsa_type = alipay.RSA2
pkcs_type = alipay.PKCS8
}
//配置公共参数
client.SetCharset("utf-8").
SetSignType(rsa_type).
SetPrivateKeyType(pkcs_type)
if notiURL != "" {
client.SetNotifyUrl(notiURL)
}
//新支付宝支付
if paySet.PayAliUseType == "1" {
client.SetAppCertSN(paySet.PayAppCertSn)
aliPayRootCertSN := "687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6"
client.SetAliPayRootCertSN(aliPayRootCertSN)
client.SetAliPayPublicCertSN(paySet.PayAlipayrsaPublicKey)
}
fmt.Println(client)
//请求参数
body := make(gopay.BodyMap)
body.Set("subject", subject)
body.Set("out_trade_no", orderID)
body.Set("total_amount", amount)
body.Set("timeout_express", "30m")
body.Set("product_code", "FAST_INSTANT_TRADE_PAY")
// body.Set("passback_params", orderID)
payParam, err := client.TradePagePay(body)
if err != nil {
return "", err
}
return payParam, nil
}

// TradeAppPay is 支付宝H5支付
func TradeWapPay(appID, priKey, subject, orderID, amount, notiURL, RSA, PKCS, page_url string, paySet *md.PayData) (string, error) {


+ 30
- 0
lib/local_wechat/api.go Целия файл

@@ -3,12 +3,14 @@ package local_wxpay
import (
zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils"
"code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils/logx"
"code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils/qrcode"
"fmt"
"github.com/iGoogle-ink/gopay"
"github.com/iGoogle-ink/gopay/pkg/util"
"github.com/iGoogle-ink/gopay/wechat"
v3 "github.com/iGoogle-ink/gopay/wechat/v3"
"strconv"
"strings"
"time"
)

@@ -124,6 +126,34 @@ func TradeH5Pay(client *wechat.Client, subject, orderID, amount, notifyUrl strin
}
return r, nil
}
func TradePcPay(client *wechat.Client, subject, orderID, amount, notifyUrl, productId string) (map[string]string, error) {
// 初始化 BodyMap
bm := make(gopay.BodyMap)
bm.Set("nonce_str", util.GetRandomString(32)).
Set("body", subject).
Set("out_trade_no", orderID).
Set("total_fee", amount).
Set("spbill_create_ip", "121.196.29.49").
Set("notify_url", notifyUrl).
Set("product_id", productId).
Set("trade_type", wechat.TradeType_Native).
Set("sign_type", wechat.SignType_MD5)
// 预下单
wxRsp, err := client.UnifiedOrder(bm)
if err != nil {
_ = zhios_pay_logx.Warn(err)
return nil, err
}
QRcode := ""
if wxRsp.CodeUrl != "" {
QRcode = qrcode.GetPNGBase64(wxRsp.CodeUrl)
}
QRcode = strings.ReplaceAll(QRcode, "\u0000", "")
r := map[string]string{
"payQrcode": QRcode,
}
return r, nil
}

// TradeMiniProgPay is 微信小程序支付 ☑️
func TradeMiniProgPay(client *wechat.Client, subject, orderID, amount, notifyUrl, openid string) (map[string]string, error) {


+ 1
- 1
lib/luso_bank/macao_luso.go Целия файл

@@ -70,7 +70,7 @@ func (s *signParam) SetSign(privateKeyStr string) error {
func (payParam *PayParam) Send(prd, isNeedEncode bool, method string) (string, error) {
url := "https://qrpaytest.lusobank.com.mo:443"
if prd {
url = "https://qrpaytest.lusobank.com.mo:8443"
url = "https://qrpay.lusobank.com.mo:443"
}
switch method {
case "create":


+ 152
- 0
md/alipay.go Целия файл

@@ -15,3 +15,155 @@ type PayData struct {
PriKey string `json:"pay_ali_new_private_key"`
WxAppletFilepathUrl string `json:"wx_applet_filepath_url"`
}

type ZhimaCreditPayafteruseCreditagreementQuery struct {
ZhimaCreditPayafteruseCreditagreementQueryResponse struct {
Code string `json:"code"`
Msg string `json:"msg"`
AgreementStatus string `json:"agreement_status"`
BizTime string `json:"biz_time"`
CreditAgreementId string `json:"credit_agreement_id"`
OutAgreementNo string `json:"out_agreement_no"`
} `json:"zhima_credit_payafteruse_creditagreement_query_response"`
AlipayCertSn string `json:"alipay_cert_sn"`
Sign string `json:"sign"`
}
type ZhimaCreditPayafteruseCreditbizorderOrder struct {
ZhimaCreditPayafteruseCreditbizorderOrderResponse struct {
Code string `json:"code"`
Msg string `json:"msg"`
OutOrderNo string `json:"out_order_no"`
CreditBizOrderId string `json:"credit_biz_order_id"`
} `json:"zhima_credit_payafteruse_creditbizorder_order_response"`
Sign string `json:"sign"`
}
type ZhimaCreditPayafteruseCreditbizorderQuery struct {
ZhimaCreditPayafteruseCreditbizorderQueryResponse struct {
Code string `json:"code"`
Msg string `json:"msg"`
CreditBizOrderId string `json:"credit_biz_order_id"`
CreditAgreementId string `json:"credit_agreement_id"`
TotalAmount float64 `json:"total_amount"`
CreateTime string `json:"create_time"`
ZmServiceId string `json:"zm_service_id"`
ProductCode string `json:"product_code"`
OrderStatus string `json:"order_status"`
TradeNo string `json:"trade_no"`
} `json:"zhima_credit_payafteruse_creditbizorder_query_response"`
Sign string `json:"sign"`
}
type AlipayFundTransUniTransfer struct {
AlipayFundTransUniTransferResponse struct {
Code string `json:"code"`
Msg string `json:"msg"`
OutBizNo string `json:"out_biz_no"`
OrderId string `json:"order_id"`
PayFundOrderId string `json:"pay_fund_order_id"`
Status string `json:"status"`
TransDate string `json:"trans_date"`
} `json:"alipay_fund_trans_uni_transfer_response"`
Sign string `json:"sign"`
}
type ZhimaCreditPayafteruseCreditbizorderFinish struct {
ZhimaCreditPayafteruseCreditbizorderFinishResponse struct {
Code string `json:"code"`
Msg string `json:"msg"`
OutRequestNo string `json:"out_request_no"`
CreditBizOrderId string `json:"credit_biz_order_id"`
OrderStatus string `json:"order_status"`
} `json:"zhima_credit_payafteruse_creditbizorder_finish_response"`
Sign string `json:"sign"`
}
type AlipayTradePay struct {
AlipayTradePayResponse struct {
Code string `json:"code"`
Msg string `json:"msg"`
TradeNo string `json:"trade_no"`
OutTradeNo string `json:"out_trade_no"`
OpenId string `json:"open_id"`
BuyerLogonId string `json:"buyer_logon_id"`
TransPayRate string `json:"trans_pay_rate"`
TotalAmount float64 `json:"total_amount"`
TransCurrency string `json:"trans_currency"`
SettleCurrency string `json:"settle_currency"`
SettleAmount string `json:"settle_amount"`
PayCurrency string `json:"pay_currency"`
PayAmount string `json:"pay_amount"`
SettleTransRate string `json:"settle_trans_rate"`
ReceiptAmount string `json:"receipt_amount"`
BuyerPayAmount float64 `json:"buyer_pay_amount"`
PointAmount float64 `json:"point_amount"`
InvoiceAmount float64 `json:"invoice_amount"`
GmtPayment string `json:"gmt_payment"`
FundBillList []struct {
FundChannel string `json:"fund_channel"`
BankCode string `json:"bank_code"`
Amount int `json:"amount"`
RealAmount float64 `json:"real_amount"`
FundType string `json:"fund_type"`
} `json:"fund_bill_list"`
CardBalance float64 `json:"card_balance"`
StoreName string `json:"store_name"`
DiscountGoodsDetail string `json:"discount_goods_detail"`
BuyerUserId string `json:"buyer_user_id"`
AsyncPaymentMode string `json:"async_payment_mode"`
VoucherDetailList []struct {
Id string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Amount int `json:"amount"`
MerchantContribute int `json:"merchant_contribute"`
OtherContribute int `json:"other_contribute"`
Memo string `json:"memo"`
TemplateId string `json:"template_id"`
OtherContributeDetail []struct {
ContributeType string `json:"contribute_type"`
ContributeAmount int `json:"contribute_amount"`
} `json:"other_contribute_detail"`
PurchaseBuyerContribute float64 `json:"purchase_buyer_contribute"`
PurchaseMerchantContribute float64 `json:"purchase_merchant_contribute"`
PurchaseAntContribute float64 `json:"purchase_ant_contribute"`
} `json:"voucher_detail_list"`
AdvanceAmount string `json:"advance_amount"`
AuthTradePayMode string `json:"auth_trade_pay_mode"`
ChargeAmount string `json:"charge_amount"`
ChargeFlags string `json:"charge_flags"`
SettlementId string `json:"settlement_id"`
BusinessParams string `json:"business_params"`
BuyerUserType string `json:"buyer_user_type"`
MdiscountAmount string `json:"mdiscount_amount"`
DiscountAmount string `json:"discount_amount"`
BuyerUserName string `json:"buyer_user_name"`
ReceiptCurrencyType string `json:"receipt_currency_type"`
CreditPayMode string `json:"credit_pay_mode"`
CreditBizOrderId string `json:"credit_biz_order_id"`
EnterprisePayInfo struct {
IsUseEnterprisePay bool `json:"is_use_enterprise_pay"`
InvoiceAmount int `json:"invoice_amount"`
BizInfo string `json:"biz_info"`
} `json:"enterprise_pay_info"`
CanTurnToAppPay string `json:"can_turn_to_app_pay"`
HybAmount string `json:"hyb_amount"`
BkagentRespInfo struct {
BindtrxId string `json:"bindtrx_id"`
BindclrissrId string `json:"bindclrissr_id"`
BindpyeracctbkId string `json:"bindpyeracctbk_id"`
BkpyeruserCode string `json:"bkpyeruser_code"`
EstterLocation string `json:"estter_location"`
} `json:"bkagent_resp_info"`
ChargeInfoList struct {
ChargeFee float64 `json:"charge_fee"`
OriginalChargeFee float64 `json:"original_charge_fee"`
SwitchFeeRate string `json:"switch_fee_rate"`
IsRatingOnTradeReceiver string `json:"is_rating_on_trade_receiver"`
IsRatingOnSwitch string `json:"is_rating_on_switch"`
ChargeType string `json:"charge_type"`
SubFeeDetailList []struct {
ChargeFee float64 `json:"charge_fee"`
OriginalChargeFee float64 `json:"original_charge_fee"`
SwitchFeeRate string `json:"switch_fee_rate"`
} `json:"sub_fee_detail_list"`
} `json:"charge_info_list"`
} `json:"alipay_trade_pay_response"`
Sign string `json:"sign"`
}

+ 5
- 4
md/boc.go Целия файл

@@ -110,10 +110,11 @@ type CreateQRTradeReq struct {

type CreateQRTradeResponse struct {
MacaoBOCPublicResponse
LogNo string `json:"logNo"`
Amount string `json:"amount"`
Result string `json:"result"`
PayURL string `json:"payUrl"`
LogNo string `json:"logNo"`
Amount string `json:"amount"`
Result string `json:"result"`
PayURL string `json:"payUrl"`
PayQrcode string `json:"payQrcode"`
}

type OfflineResultResponse struct {


+ 417
- 0
pay/alipay.go Целия файл

@@ -0,0 +1,417 @@
package pay

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/md"
zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils"
"encoding/json"
"errors"
"fmt"
"github.com/iGoogle-ink/gopay"
"github.com/iGoogle-ink/gopay/alipay"
"github.com/iGoogle-ink/gopay/pkg/util"
"github.com/iGoogle-ink/gopay/pkg/xhttp"
"github.com/iGoogle-ink/gopay/pkg/xlog"
"time"
)

const (
baseUrl = "https://openapi.alipay.com/gateway.do"
sandboxBaseUrl = "https://openapi.alipaydev.com/gateway.do"
baseUrlUtf8 = "https://openapi.alipay.com/gateway.do?charset=utf-8"
sandboxBaseUrlUtf8 = "https://openapi.alipaydev.com/gateway.do?charset=utf-8"
)

func Comm(args map[string]string) *alipay.Client {
paySet := AlipayCofing(args)
if args["private_key"] == "" || args["app_id"] == "" {
return nil
}
//初始化支付宝客户端
// appID 是在支付宝申请的APPID
// priKey 是支付宝私钥
// code 支付宝授权码
client := alipay.NewClient(args["app_id"], args["private_key"], true)
client.DebugSwitch = gopay.DebugOn
//判断密钥的类型
rsa_type := alipay.RSA2
pkcs_type := alipay.PKCS1
if args["rsa"] == "1" {
rsa_type = alipay.RSA
}
if args["pkcs"] == "1" {
pkcs_type = alipay.PKCS8
}
if paySet.PayAliUseType == "1" {
rsa_type = alipay.RSA2
pkcs_type = alipay.PKCS8
}
//配置公共参数
client.SetCharset("utf-8").
SetSignType(rsa_type).
SetPrivateKeyType(pkcs_type)
//新支付宝支付
if paySet.PayAliUseType == "1" {
client.SetAppCertSN(paySet.PayAppCertSn)
aliPayRootCertSN := "687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6"
client.SetAliPayRootCertSN(aliPayRootCertSN)
client.SetAliPayPublicCertSN(paySet.PayAlipayrsaPublicKey)
}
client.IsProd = true
fmt.Println(client)
return client

}
func OpenAuthTokenApp(args map[string]string) (*alipay.SystemOauthTokenResponse, error) {
client := Comm(args)
if client == nil {
return nil, errors.New("获取失败")
}
//请求参数
body := make(gopay.BodyMap)
body.Set("grant_type", "authorization_code")
body.Set("code", args["code"])

payParam, err := client.SystemOauthToken(body)
if err != nil {
return nil, err
}
return payParam, nil
}
func UserInfoShare(args map[string]string) (*alipay.UserInfoShareResponse, error) {
client := Comm(args)
client.AuthToken = args["auth_token"]
if client == nil {
return nil, errors.New("获取失败")
}
payParam, err := client.UserInfoShare()
if err != nil {
return nil, err
}
return payParam, nil
}

func CreditagreementSign(args map[string]string) (string, error) {
client := Comm(args)
client.AppAuthToken = args["app_auth_token"]
if client == nil {
return "", errors.New("获取失败")
}
//请求参数
bm := make(gopay.BodyMap)
// biz_content
bm.SetBodyMap("biz_content", func(bz gopay.BodyMap) {
bz.Set("out_agreement_no", args["out_agreement_no"])
bz.Set("zm_service_id", args["zm_service_id"])
bz.Set("category_id", args["category_id"])
bz.Set("return_back_link", args["return_back_link"])
})

aliPsp := ""
bs, err := PostAliPayAPISelfV2(client, bm, "zhima.credit.payafteruse.creditagreement.sign", &aliPsp)
if err != nil {
xlog.Error(err)
return "", err
}
return zhios_pay_utils.AnyToString(bs), nil
}
func CreditagreementQuery(args map[string]string) (*md.ZhimaCreditPayafteruseCreditagreementQuery, error) {
client := Comm(args)
client.AppAuthToken = args["app_auth_token"]
if client == nil {
return nil, errors.New("获取失败")
}
//请求参数
bm := make(gopay.BodyMap)
// biz_content
bm.SetBodyMap("biz_content", func(bz gopay.BodyMap) {
bz.Set("out_agreement_no", args["out_agreement_no"])
})

var aliPsp md.ZhimaCreditPayafteruseCreditagreementQuery
bs, err := PostAliPayAPISelfV2(client, bm, "zhima.credit.payafteruse.creditagreement.query", &aliPsp)
if err != nil {
xlog.Error(err)
return nil, err
}
res := bs.(*md.ZhimaCreditPayafteruseCreditagreementQuery)
return res, nil
}

//信用下单
func CreditagreementOrder(args map[string]string) (*md.ZhimaCreditPayafteruseCreditbizorderOrder, error) {
client := Comm(args)
client.AppAuthToken = args["app_auth_token"]
if client == nil {
return nil, errors.New("获取失败")
}
//请求参数
bm := make(gopay.BodyMap)
// biz_content
bm.SetBodyMap("biz_content", func(bz gopay.BodyMap) {
bz.Set("out_order_no", args["out_order_no"])
bz.Set("credit_agreement_id", args["credit_agreement_id"])
bz.Set("category_id", args["category_id"])
bz.Set("order_amount", args["order_amount"])
bz.Set("amount_type", args["amount_type"])
bz.Set("subject", args["subject"])
})

var aliPsp md.ZhimaCreditPayafteruseCreditbizorderOrder
bs, err := PostAliPayAPISelfV2(client, bm, "zhima.credit.payafteruse.creditbizorder.order", &aliPsp)
if err != nil {
xlog.Error(err)
return nil, err
}
res := bs.(*md.ZhimaCreditPayafteruseCreditbizorderOrder)
return res, nil
}

//查询信用订单
func CreditagreementOrderQuery(args map[string]string) (*md.ZhimaCreditPayafteruseCreditbizorderQuery, error) {
client := Comm(args)
client.AppAuthToken = args["app_auth_token"]
if client == nil {
return nil, errors.New("获取失败")
}
//请求参数
bm := make(gopay.BodyMap)
// biz_content
bm.SetBodyMap("biz_content", func(bz gopay.BodyMap) {
bz.Set("credit_biz_order_id", args["credit_biz_order_id"])
})

var aliPsp md.ZhimaCreditPayafteruseCreditbizorderQuery
bs, err := PostAliPayAPISelfV2(client, bm, "zhima.credit.payafteruse.creditbizorder.query", &aliPsp)
if err != nil {
xlog.Error(err)
return nil, err
}
res := bs.(*md.ZhimaCreditPayafteruseCreditbizorderQuery)
return res, nil
}

//转账
func AlipayFundTransUniTransfer(args map[string]string) (*md.AlipayFundTransUniTransfer, error) {
client := Comm(args)
if client == nil {
return nil, errors.New("获取失败")
}
//请求参数
bm := make(gopay.BodyMap)
// biz_content
payeeInfo := map[string]string{
"identity": args["identity"],
"identity_type": args["identity_type"],
"name": args["name"],
}
bm.SetBodyMap("biz_content", func(bz gopay.BodyMap) {
bz.Set("out_biz_no", args["out_biz_no"])
bz.Set("trans_amount", args["trans_amount"])
bz.Set("product_code", args["product_code"])
bz.Set("biz_scene", args["biz_scene"])
bz.Set("order_title", args["order_title"])
bz.Set("payee_info", payeeInfo)
})

var aliPsp md.AlipayFundTransUniTransfer
bs, err := PostAliPayAPISelfV2(client, bm, "alipay.fund.trans.uni.transfer", &aliPsp)
if err != nil {
xlog.Error(err)
return nil, err
}
res := bs.(*md.AlipayFundTransUniTransfer)
return res, nil
}

//扣款
func AlipayTradePay(args map[string]string) (*md.AlipayTradePay, error) {
client := Comm(args)
if args["notify_url"] != "" {
client.NotifyUrl = args["notify_url"]
}
if client == nil {
return nil, errors.New("获取失败")
}
//请求参数
bm := make(gopay.BodyMap)
// biz_content
extendParams := map[string]string{
"creditTradeScene": args["creditTradeScene"],
}
bm.SetBodyMap("biz_content", func(bz gopay.BodyMap) {
bz.Set("out_trade_no", args["out_trade_no"])
bz.Set("is_async_pay", args["is_async_pay"])
bz.Set("total_amount", args["total_amount"])
bz.Set("auth_code", args["auth_code"])
bz.Set("product_code", args["product_code"])
bz.Set("scene", args["scene"])
bz.Set("subject", args["subject"])
bz.Set("extend_params", extendParams)
})
var aliPsp md.AlipayTradePay
v2, err := PostAliPayAPISelfV2(client, bm, "alipay.trade.pay", &aliPsp)
if err != nil {
xlog.Error(err)
return nil, err
}
res := v2.(*md.AlipayTradePay)
return res, nil
}
func AlipayTradeQuery(args map[string]string) (*md.AlipayFundTransUniTransfer, error) {
client := Comm(args)
if client == nil {
return nil, errors.New("获取失败")
}
//请求参数
bm := make(gopay.BodyMap)
bm.SetBodyMap("biz_content", func(bz gopay.BodyMap) {
bz.Set("out_trade_no", args["out_trade_no"])
})

var aliPsp md.AlipayFundTransUniTransfer
bs, err := PostAliPayAPISelfV2(client, bm, "alipay.trade.query", &aliPsp)
if err != nil {
xlog.Error(err)
return nil, err
}
res := bs.(*md.AlipayFundTransUniTransfer)
return res, nil
}

//结束信用服务订单
func CreditagreementOrderFinish(args map[string]string) (*md.ZhimaCreditPayafteruseCreditbizorderFinish, error) {
client := Comm(args)
client.AppAuthToken = args["app_auth_token"]
if client == nil {
return nil, errors.New("获取失败")
}
//请求参数
bm := make(gopay.BodyMap)
// biz_content
bm.SetBodyMap("biz_content", func(bz gopay.BodyMap) {
bz.Set("out_request_no", args["out_request_no"])
bz.Set("credit_biz_order_id", args["credit_biz_order_id"])
bz.Set("is_fulfilled", args["is_fulfilled"])
bz.Set("remark", args["remark"])
})

var aliPsp md.ZhimaCreditPayafteruseCreditbizorderFinish
bs, err := PostAliPayAPISelfV2(client, bm, "zhima.credit.payafteruse.creditbizorder.finish", &aliPsp)
if err != nil {
xlog.Error(err)
return nil, err
}
res := bs.(*md.ZhimaCreditPayafteruseCreditbizorderFinish)
return res, nil
}

func PostAliPayAPISelfV2(a *alipay.Client, bm gopay.BodyMap, method string, aliRsp interface{}) (aliRsps interface{}, err error) {
var (
bs, bodyBs []byte
)
// check if there is biz_content
bz := bm.GetInterface("biz_content")
if bzBody, ok := bz.(gopay.BodyMap); ok {
if bodyBs, err = json.Marshal(bzBody); err != nil {
return aliRsp, fmt.Errorf("json.Marshal(%v):%w", bzBody, err)
}
bm.Set("biz_content", string(bodyBs))
}

if bs, err = doAliPaySelf(a, bm, method); err != nil {
return aliRsp, err
}
switch method {
case "alipay.trade.app.pay":
return string(bs), nil
case "alipay.trade.wap.pay", "alipay.trade.page.pay", "alipay.user.certify.open.certify", "zhima.credit.payafteruse.creditagreement.sign":
return string(bs), nil
default:
if err = json.Unmarshal(bs, aliRsp); err != nil {
return aliRsp, err
}
return aliRsp, nil
}
}

// 向支付宝发送自定义请求
func doAliPaySelf(a *alipay.Client, bm gopay.BodyMap, method string) (bs []byte, err error) {
var (
url, sign string
)
bm.Set("method", method)

// check public parameter
checkPublicParam(a, bm)

// check sign
if bm.GetString("sign") == "" {
sign, err = alipay.GetRsaSign(bm, bm.GetString("sign_type"), a.PrivateKeyType, a.PrivateKey)
if err != nil {
return nil, fmt.Errorf("GetRsaSign Error: %v", err)
}
bm.Set("sign", sign)
}

if a.DebugSwitch == gopay.DebugOn {
req, _ := json.Marshal(bm)
xlog.Debugf("Alipay_Request: %s", req)
}
param := alipay.FormatURLParam(bm)
switch method {
case "alipay.trade.app.pay":
return []byte(param), nil
case "alipay.trade.wap.pay", "alipay.trade.page.pay", "alipay.user.certify.open.certify", "zhima.credit.payafteruse.creditagreement.sign":
return []byte(baseUrl + "?" + param), nil
default:
httpClient := xhttp.NewClient()
url = baseUrlUtf8
res, bs, errs := httpClient.Type(xhttp.TypeForm).Post(url).SendString(param).EndBytes()
if len(errs) > 0 {
return nil, errs[0]
}
if a.DebugSwitch == gopay.DebugOn {
xlog.Debugf("Alipay_Response: %s%d %s%s", xlog.Red, res.StatusCode, xlog.Reset, string(bs))
}
if res.StatusCode != 200 {
return nil, fmt.Errorf("HTTP Request Error, StatusCode = %d", res.StatusCode)
}
return bs, nil
}
}
func checkPublicParam(a *alipay.Client, bm gopay.BodyMap) {
bm.Set("format", "JSON")

if bm.GetString("app_id") == "" && a.AppId != util.NULL {
bm.Set("app_id", a.AppId)
}
if bm.GetString("app_cert_sn") == "" && a.AppCertSN != util.NULL {
bm.Set("app_cert_sn", a.AppCertSN)
}
if bm.GetString("alipay_root_cert_sn") == "" && a.AliPayRootCertSN != util.NULL {
bm.Set("alipay_root_cert_sn", a.AliPayRootCertSN)
}
if bm.GetString("return_url") == "" && a.ReturnUrl != util.NULL {
bm.Set("return_url", a.ReturnUrl)
}
bm.Set("charset", "utf-8")
if bm.GetString("charset") == "" && a.Charset != util.NULL {
bm.Set("charset", a.Charset)
}
bm.Set("sign_type", alipay.RSA2)
if bm.GetString("sign_type") == "" && a.SignType != util.NULL {
bm.Set("sign_type", a.SignType)
}
bm.Set("timestamp", time.Now().Format(util.TimeLayout))

bm.Set("version", "1.0")
if bm.GetString("notify_url") == "" && a.NotifyUrl != util.NULL {
bm.Set("notify_url", a.NotifyUrl)
}
if bm.GetString("app_auth_token") == "" && a.AppAuthToken != util.NULL {
bm.Set("app_auth_token", a.AppAuthToken)
}
if bm.GetString("auth_token") == "" && a.AuthToken != util.NULL {
bm.Set("auth_token", a.AuthToken)
}
}

+ 19
- 1
pay/pay_by_own.go Целия файл

@@ -51,7 +51,20 @@ func AlipayApp(args map[string]string) (string, error) {
}
return zhios_pay_utils.AnyToString(param), nil
}

func AlipayPc(args map[string]string) (string, error) {
paySet := AlipayCofing(args)
if args["private_key"] == "" || args["app_id"] == "" {
return "", errors.New("请在后台正确配置支付宝")
}
param, err := local_alipay.TradeAppPc(args["app_id"], args["private_key"], args["subject"], args["ord_id"], args["amount"], args["notify_url"], args["rsa"], args["pkcs"], paySet)
if err != nil {
fmt.Println("支付宝错误日志")
fmt.Println(param)
fmt.Println(err)
return "", errors.New("支付宝订单创建失败")
}
return zhios_pay_utils.AnyToString(param), nil
}
func AlipayWap(args map[string]string) (string, error) {
paySet := AlipayCofing(args)
if args["private_key"] == "" || args["app_id"] == "" {
@@ -95,6 +108,11 @@ func WxH5Pay(params map[string]string) (map[string]string, error) {
r, err := local_wxpay.TradeH5Pay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"])
return r, err
}
func WxPcPay(params map[string]string) (map[string]string, error) {
client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true)
r, err := local_wxpay.TradePcPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"], params["product_id"])
return r, err
}

// 微信小程序v2
func WxMiniProgPay(params map[string]string) (map[string]string, error) {


+ 86
- 0
test/fb_pay_test.go Целия файл

@@ -77,3 +77,89 @@ func TestFBPayOrderWxconfig(t *testing.T) {
}
t.Logf("回调数据:%s\n", send)
}

func TestFBAccreditQuery(t *testing.T) {
requestParameters := fb.GetRequestParametersByVendorSn("2022120518415543840a")
requestParameters.Method = "openapi.share.accredit.query"
requestParameters.SignMethod = "md5"
requestParameters.Nonce = time.Now().Format("20060102150405")
param := make(map[string]interface{})
param["merchant_id"] = 1989190
for key, value := range param {
if value == "" {
delete(param, key)
}
}
requestParameters.SetBizContent(param)
requestParameters.SetSign("c5d47b9e515594313d80fb9903ece2d8")
send, err := requestParameters.Send(false)
if err != nil {
t.Error(err)
}
t.Logf("回调数据:%s\n", send)
}

func TestFBAccountOrderSwitch(t *testing.T) {
requestParameters := fb.GetRequestParametersByVendorSn("2022120518415543840a")
requestParameters.Method = "openapi.agent.account.order.switch"
requestParameters.SignMethod = "md5"
requestParameters.Nonce = time.Now().Format("20060102150405")
param := make(map[string]interface{})
param["merchant_id"] = 1989190
param["state"] = 1
param["share_percent"] = 60
for key, value := range param {
if value == "" {
delete(param, key)
}
}
requestParameters.SetBizContent(param)
requestParameters.SetSign("c5d47b9e515594313d80fb9903ece2d8")
send, err := requestParameters.Send(false)
if err != nil {
t.Error(err)
}
t.Logf("回调数据:%s\n", send)
}

func TestFBMerchantIncomeSuccess(t *testing.T) {
requestParameters := fb.GetRequestParametersByVendorSn("2022120518415543840a")
requestParameters.Method = "openapi.merchant.income.status.query"
requestParameters.SignMethod = "md5"
requestParameters.Nonce = time.Now().Format("20060102150405")
param := make(map[string]interface{})
param["merchant_code"] = "139334168531126"
for key, value := range param {
if value == "" {
delete(param, key)
}
}
requestParameters.SetBizContent(param)
requestParameters.SetSign("c5d47b9e515594313d80fb9903ece2d8")
send, err := requestParameters.Send(false)
if err != nil {
t.Error(err)
}
t.Logf("回调数据:%s\n", send)
}

func TestFBUrlSet(t *testing.T) {
requestParameters := fb.GetRequestParametersByVendorSn("2022120518415543840a")
requestParameters.Method = "fbpay.pay.callback.config"
requestParameters.SignMethod = "md5"
requestParameters.Nonce = time.Now().Format("20060102150405")
param := make(map[string]interface{})
param["second_callback_url"] = "http://api.zhiyingos.com/api/v1/comm/pay/fb/callback"
for key, value := range param {
if value == "" {
delete(param, key)
}
}
requestParameters.SetBizContent(param)
requestParameters.SetSign("c5d47b9e515594313d80fb9903ece2d8")
send, err := requestParameters.Send(false)
if err != nil {
t.Error(err)
}
t.Logf("回调数据:%s\n", send)
}

+ 33
- 0
utils/qrcode/decodeFile.go Целия файл

@@ -0,0 +1,33 @@
package qrcode

import (
"image"
_ "image/jpeg"
_ "image/png"
"os"

"github.com/makiuchi-d/gozxing"
"github.com/makiuchi-d/gozxing/qrcode"
)

func DecodeFile(fi string) (string, error) {
file, err := os.Open(fi)
if err != nil {
return "", err
}
img, _, err := image.Decode(file)
if err != nil {
return "", err
}
// prepare BinaryBitmap
bmp, err := gozxing.NewBinaryBitmapFromImage(img)
if err != nil {
return "", err
}
// decode image
result, err := qrcode.NewQRCodeReader().Decode(bmp, nil)
if err != nil {
return "", err
}
return result.String(), nil
}

+ 43
- 0
utils/qrcode/getBase64.go Целия файл

@@ -0,0 +1,43 @@
package qrcode

// 生成登录二维码图片, 方便在网页上显示

import (
"bytes"
"encoding/base64"
"image/jpeg"
"image/png"

"github.com/boombuler/barcode"
"github.com/boombuler/barcode/qr"
)

func GetJPGBase64(content string, edges ...int) string {
edgeLen := 300
if len(edges) > 0 && edges[0] > 100 && edges[0] < 2000 {
edgeLen = edges[0]
}
img, _ := qr.Encode(content, qr.L, qr.Unicode)
img, _ = barcode.Scale(img, edgeLen, edgeLen)

emptyBuff := bytes.NewBuffer(nil) // 开辟一个新的空buff缓冲区
jpeg.Encode(emptyBuff, img, nil)
dist := make([]byte, 50000) // 开辟存储空间
base64.StdEncoding.Encode(dist, emptyBuff.Bytes()) // buff转成base64
return "data:image/png;base64," + string(dist) // 输出图片base64(type = []byte)
}

func GetPNGBase64(content string, edges ...int) string {
edgeLen := 300
if len(edges) > 0 && edges[0] > 100 && edges[0] < 2000 {
edgeLen = edges[0]
}
img, _ := qr.Encode(content, qr.L, qr.Unicode)
img, _ = barcode.Scale(img, edgeLen, edgeLen)

emptyBuff := bytes.NewBuffer(nil) // 开辟一个新的空buff缓冲区
png.Encode(emptyBuff, img)
dist := make([]byte, 50000) // 开辟存储空间
base64.StdEncoding.Encode(dist, emptyBuff.Bytes()) // buff转成base64
return string(dist) // 输出图片base64(type = []byte)
}

+ 85
- 0
utils/qrcode/saveFile.go Целия файл

@@ -0,0 +1,85 @@
package qrcode

// 生成登录二维码图片

import (
"errors"
"image"
"image/jpeg"
"image/png"
"os"
"path/filepath"
"strings"

"github.com/boombuler/barcode"
"github.com/boombuler/barcode/qr"
)

func SaveJpegFile(filePath, content string, edges ...int) error {
edgeLen := 300
if len(edges) > 0 && edges[0] > 100 && edges[0] < 2000 {
edgeLen = edges[0]
}
img, _ := qr.Encode(content, qr.L, qr.Unicode)
img, _ = barcode.Scale(img, edgeLen, edgeLen)

return writeFile(filePath, img, "jpg")
}

func SavePngFile(filePath, content string, edges ...int) error {
edgeLen := 300
if len(edges) > 0 && edges[0] > 100 && edges[0] < 2000 {
edgeLen = edges[0]
}
img, _ := qr.Encode(content, qr.L, qr.Unicode)
img, _ = barcode.Scale(img, edgeLen, edgeLen)

return writeFile(filePath, img, "png")
}

func writeFile(filePath string, img image.Image, format string) error {
if err := createDir(filePath); err != nil {
return err
}
file, err := os.Create(filePath)
defer file.Close()
if err != nil {
return err
}
switch strings.ToLower(format) {
case "png":
err = png.Encode(file, img)
break
case "jpg":
err = jpeg.Encode(file, img, nil)
default:
return errors.New("format not accept")
}
if err != nil {
return err
}
return nil
}

func createDir(filePath string) error {
var err error
// filePath, _ = filepath.Abs(filePath)
dirPath := filepath.Dir(filePath)
dirInfo, err := os.Stat(dirPath)
if err != nil {
if !os.IsExist(err) {
err = os.MkdirAll(dirPath, 0777)
if err != nil {
return err
}
} else {
return err
}
} else {
if dirInfo.IsDir() {
return nil
}
return errors.New("directory is a file")
}
return nil
}

+ 39
- 0
utils/qrcode/writeWeb.go Целия файл

@@ -0,0 +1,39 @@
package qrcode

import (
"bytes"
"image/jpeg"
"image/png"
"net/http"

"github.com/boombuler/barcode"
"github.com/boombuler/barcode/qr"
)

func WritePng(w http.ResponseWriter, content string, edges ...int) error {
edgeLen := 300
if len(edges) > 0 && edges[0] > 100 && edges[0] < 2000 {
edgeLen = edges[0]
}
img, _ := qr.Encode(content, qr.L, qr.Unicode)
img, _ = barcode.Scale(img, edgeLen, edgeLen)
buff := bytes.NewBuffer(nil)
png.Encode(buff, img)
w.Header().Set("Content-Type", "image/png")
_, err := w.Write(buff.Bytes())
return err
}

func WriteJpg(w http.ResponseWriter, content string, edges ...int) error {
edgeLen := 300
if len(edges) > 0 && edges[0] > 100 && edges[0] < 2000 {
edgeLen = edges[0]
}
img, _ := qr.Encode(content, qr.L, qr.Unicode)
img, _ = barcode.Scale(img, edgeLen, edgeLen)
buff := bytes.NewBuffer(nil)
jpeg.Encode(buff, img, nil)
w.Header().Set("Content-Type", "image/jpg")
_, err := w.Write(buff.Bytes())
return err
}

Зареждане…
Отказ
Запис