|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- package svc
-
- import (
- "applet/app/pay/md"
- svcComm "applet/app/svc"
- "applet/app/utils"
- "applet/app/utils/logx"
- "encoding/json"
- "encoding/xml"
- "fmt"
- "github.com/gin-gonic/gin"
- "github.com/iGoogle-ink/gopay"
- "io/ioutil"
- "net/url"
- )
-
- // PayFuncList 支付参数
- var PayFuncList = map[string]map[string]func(*gin.Context) (interface{}, error){
-
- }
-
- // PayCallbackFuncList 回调
- var PayCallbackFuncList = map[string]map[string]func(*gin.Context){
-
- }
-
- // PayRefundFuncList 退款
- var PayRefundFuncList = map[string]map[string]func(*gin.Context, string){
- // 自营商品商品
- md.MallGoods: {
- md.BALANCE_PAY: nil,
- md.ALIPAY: nil,
- md.WX_PAY: nil,
- },
- }
-
- // PayStatusFuncList 支付状态
- var PayStatusFuncList = map[string]func(*gin.Context) (interface{}, error){
- // 商学院
- // md.BusinessCollege: PayStatus,
- }
-
- // GetAllPayMethodList 获取支付列表
- func GetAllPayMethodList(c *gin.Context) map[string]map[string]string {
- user := svcComm.GetUser(c)
- return map[string]map[string]string{
- md.BALANCE_PAY: {
- "name": md.PayMethod[md.BALANCE_PAY],
- "sub_name": "当前余额:¥" + user.Profile.FinValid,
- "type": md.BALANCE_PAY,
- "icon": svcComm.OffImageFormat(c, "balance.png"),
- },
- md.WX_PAY: {
- "name": md.PayMethod[md.WX_PAY],
- "sub_name": "使用微信支付",
- "type": md.WX_PAY,
- "icon": svcComm.OffImageFormat(c, "wx_pay.png"),
- },
- md.ALIPAY: {
- "name": md.PayMethod[md.ALIPAY],
- "sub_name": "使用支付宝支付",
- "type": md.ALIPAY,
- "icon": svcComm.OffImageFormat(c, "alipay.png"),
- },
- }
- }
-
- // GetAllPayMethodArray 获取支付列表--接口用
- func GetAllPayMethodArray(c *gin.Context) []map[string]string {
- user := svcComm.GetUser(c)
- return []map[string]string{
- {
- "name": md.PayMethod[md.BALANCE_PAY],
- "sub_name": "当前余额:¥" + user.Profile.FinValid,
- "type": md.BALANCE_PAY,
- "icon": svcComm.ImageFormat(c, "balance.png"),
- },
- {
- "name": md.PayMethod[md.WX_PAY],
- "sub_name": "使用微信支付",
- "type": md.WX_PAY,
- "icon": svcComm.ImageFormat(c, "wx_pay.png"),
- },
- {
- "name": md.PayMethod[md.ALIPAY],
- "sub_name": "使用支付宝支付",
- "type": md.ALIPAY,
- "icon": svcComm.ImageFormat(c, "alipay.png"),
- },
- }
- }
-
- func CheckAllCallbackParams(c *gin.Context) (interface{}, string, string) {
- body, _ := ioutil.ReadAll(c.Request.Body)
- dataAlipay, _ := GetAlipayCallbackParams(body)
- if dataAlipay != nil && dataAlipay.PayMethod == md.ALIPAY {
- return dataAlipay, dataAlipay.OrderType, dataAlipay.PayMethod
- }
- dataWxPay, _ := GetWxPayCallbackParams(body)
- if dataWxPay != nil && dataWxPay.PayMethod == md.WX_PAY {
- return dataWxPay, dataWxPay.OrderType, dataWxPay.PayMethod
- }
- return nil, "", ""
- }
-
- // GetAlipayCallbackParams 支付宝参数解析
- func GetAlipayCallbackParams(body []byte) (*md.AliPayCallback, error) {
- //decodeArgs := "order_type=privilege_card&pay_method=alipay&master_id=123456&gmt_create=2021-01-06+15%3A33%3A18&charset=utf-8&seller_email=1666296478%40qq.com&subject=%E6%B5%8B%E8%AF%95&sign=ILbQtP7E51hcdKaroi%2FKlefltw%2BaSOeaqgvBhYIcIuRy5yy440OIOdxPEvhTITA%2BHnA1Lgf3STepzzHVmvvTFIGeKL%2FVvz%2FLSI7vXGpUBxcw2entVZCzhmblGAB8hiK4EOHBIfUAQiyo9ePWl63p%2B%2BvS4CQuZe8SFXrFaj2bTnRyBPemxekudU8TP8tZd630SzHx7kOHYqxTYZ7kHMrLK0fjIdSWBHtSD2cocm%2FxVQ3wYXUyyfZwwTpcXLW9ao97Uj1hZSnknuFRtMfvE57D5f4W3cB%2Bnp%2B39xpuvfbBlbXXllzKUfkWVBqV6zebYMnzaogwVN%2FDXgp74BQOzkJYvA%3D%3D&buyer_id=2088012352245491&invoice_amount=0.01¬ify_id=2021010600222153319045491449160553&fund_bill_list=%5B%7B%22amount%22%3A%220.01%22%2C%22fundChannel%22%3A%22PCREDIT%22%7D%5D¬ify_type=trade_status_sync&trade_status=TRADE_SUCCESS&receipt_amount=0.01&app_id=2016120103683451&buyer_pay_amount=0.01&sign_type=RSA2&seller_id=2088221294035253&gmt_payment=2021-01-06+15%3A33%3A18¬ify_time=2021-01-06+15%3A33%3A19&passback_params=706160991839039994&version=1.0&out_trade_no=791161468268877545&total_amount=0.01&trade_no=2021010622001445491401511921&auth_app_id=2016120103683451&buyer_logon_id=150****0420&point_amount=0.00"
- decodeArgs, err := url.QueryUnescape(string(body))
- if err != nil {
- _ = logx.Warn(err)
- return nil, logx.Warn("回调参数解码错误")
- }
- data, err := url.ParseQuery(decodeArgs)
- if err != nil {
- return nil, err
- }
- dataMap := make(map[string]interface{})
- for k := range data {
- dataMap[k] = data.Get(k)
- }
- callbackStr := utils.Serialize(dataMap)
- fmt.Println("支付宝回调数据", string(callbackStr))
- var args md.AliPayCallback
- if err := json.Unmarshal(callbackStr, &args); err != nil {
- return nil, logx.Warn(err)
- }
- return &args, nil
- }
-
- // GetWxPayCallbackParams 微信回调参数解析
- func GetWxPayCallbackParams(body []byte) (*md.WxPayCallback, error) {
- dataMap := make(gopay.BodyMap)
- if err := xml.Unmarshal(body, &dataMap); err != nil {
- return nil, fmt.Errorf("xml.Unmarshal(%s):%w", string(body), err)
- }
- callbackStr := utils.Serialize(dataMap)
- fmt.Println("微信回调数据", string(callbackStr))
- var args md.WxPayCallback
- err := json.Unmarshal(callbackStr, &args)
- if err != nil {
- fmt.Println("err3")
- return nil, logx.Warn(err)
- }
- return &args, nil
- }
|