main
parent
5e4da57109
commit
3441b272ec
@ -1,31 +0,0 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"gold-shop/errors"
|
||||
request "gold-shop/request/manage"
|
||||
"gold-shop/service"
|
||||
"gold-shop/utils/excel"
|
||||
"gold-shop/utils/result"
|
||||
)
|
||||
|
||||
func GetOrders(c *gin.Context) (result.Data, error) {
|
||||
var req request.OrderQueryRequest
|
||||
err := c.ShouldBindQuery(&req)
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("参数错误")
|
||||
}
|
||||
orders, total := service.OrderService.GetOrders(req)
|
||||
data := result.Data{
|
||||
"records": orders,
|
||||
"total": total,
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func DownloadOrders(c *gin.Context) {
|
||||
var req request.OrderQueryRequest
|
||||
_ = c.ShouldBindQuery(&req)
|
||||
f := service.OrderService.GenerateOrdersExcel(req)
|
||||
excel.Download(f, "订单列表.xlsx", c)
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"gold-shop/errors"
|
||||
request "gold-shop/request/manage"
|
||||
"gold-shop/service"
|
||||
"gold-shop/utils/excel"
|
||||
"gold-shop/utils/result"
|
||||
)
|
||||
|
||||
func GetPayments(c *gin.Context) (result.Data, error) {
|
||||
var req request.PaymentQueryRequest
|
||||
err := c.ShouldBindQuery(&req)
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("参数错误")
|
||||
}
|
||||
records, total := service.PaymentService.GetPayments(req)
|
||||
data := result.Data{
|
||||
"records": records,
|
||||
"total": total,
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func DownloadPayments(c *gin.Context) {
|
||||
var req request.PaymentQueryRequest
|
||||
_ = c.ShouldBindQuery(&req)
|
||||
f := service.PaymentService.GeneratePaymentsExcel(req)
|
||||
excel.Download(f, "支付列表.xlsx", c)
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gold-shop/errors"
|
||||
request "gold-shop/request/manage"
|
||||
"gold-shop/service"
|
||||
"gold-shop/utils/excel"
|
||||
"gold-shop/utils/result"
|
||||
)
|
||||
|
||||
func GetUsers(c *gin.Context) (result.Data, error) {
|
||||
var req request.UserQueryRequest
|
||||
err := c.ShouldBindQuery(&req)
|
||||
fmt.Println("ssp", req)
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("参数错误")
|
||||
}
|
||||
users, total := service.UserService.GetUsers(req)
|
||||
data := result.Data{
|
||||
"records": users,
|
||||
"total": total,
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func DownloadUsers(c *gin.Context) {
|
||||
var req request.UserQueryRequest
|
||||
_ = c.ShouldBindQuery(&req)
|
||||
f := service.UserService.GenerateUsersExcel(req)
|
||||
excel.Download(f, "用户列表.xlsx", c)
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
server:
|
||||
port: 9090
|
||||
domain: "http://pay.hexidongkeji.top"
|
||||
alipay:
|
||||
app-id: "2021004129619376"
|
||||
private-key: "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQChC/5Psy+biyzdT/CkCknQKax44Ol0i6kAWVkw4BYERevISFqOHpVmlztcnYGx3LIDOeReYQ0ghLLT+6oGrymXzPbIOE+PTUEpPfIRdB8P96mkcbuZ7MnMCsA1vXSjYezVIAu8vdzp4FL2H1p3+gwhuLGT5w9tOUZmNAkKI8xEQwXeFDWlQ5G9w5unigEGnlODqxcStrvL14pceqsA3bm9sEDuSqVAmBXbEZxZyWnYoRJj4kNMqYIXLXwsPzE8268B+0NT9plzv8mGBI2jkwBTXvc1TjnAIK6O0vRfAz82Jz6RhMwIIOrA65F1oO44bihd/4lH+FjrMy5nYeEuBZeZAgMBAAECggEBAJ/EPi7jHL+6em+z9o9GhaO1NB1XQ0MTqj1mZk1OgYkLtLWk0fFb9eso7QMcXqYMw6zfqebXcSZpft8+M5cd/q1R8SEAfC01/wbjJVqbUJWOpQU2r14swqVhpP2rTiMn6sQkXoCH+rkqiiMRR7buoUpy5/hKqcs5ntWVmcItcV/lZ/SOshXIY1Pff9WcJkNUQqtM8OizjSA1htc3XencsOroU6KKLnVdBcGYQJQtr7hBQshgGiaNKapv6n/qGV6J6V7uBuSfwZhNXo0GxbBqZHW3LCesipPkNAvYCu+DhpqVr+j44apGhZ56cIhqdYCrnPrMKysvYHnQ7sm3GhwnimECgYEA5WeTVLkRj7gmcWQQn7KobUxfdQXZguJdVYguTwbWENbZRTDxlv3aZvivAMDx9xDfEd58/xqm5mUathxG8M/HINJ9u32elhFLXLHPD5QzCqv4+X+dZmtnnqEHa5smSEpFL2vJ7v8FGnrAqXiZVye7uqcT7j/6hCZol+EZ1SPz6g8CgYEAs7emjtDwKyzyO1kRQfTB/smlS/hfIvknZZKQoYYRgiB60f2t6aDJOzjUMCIgClWpQztDzbKonKx1ykCmiSgtUJF9MVP4iz5cJKc0wdnjO20DxFJGMHl89ejlfrfmM5D1E0d2l7kpO6M/66mjNT7fGtAdorAw8OzKbZh/KCfsq9cCgYEApWEL95ILtP5eyHQI//f+L/1U+7oh2pdyDc1FBTe6bx1UOOtV3zJWltFE6Fgwl5qUFf+9QPNnysSsgwjTo5tGxMS6W8Xt4+XH3KVazrJaMaFUthln0YQwiU0xWkPZT1grlEoyo5c5iKNh7UrB0PEWBzOXzLRW15oQ4R0oUF3A48UCgYARV4Nm/JpwUCH/wBR+PNQLdgHRVuI3SbuXfZEfRQSjfebcJJKHnNBOOqmfC2v0E1gF+M4OJ1NF6w5iueJYEdxtjdx6yhONvDLABrJ8kj3vGhHm+9lyDAcW46Zhl/VKvI4pkhfLhD6KVrJwVyo8lRiKSdLSRBY06WSPNsvuYAvieQKBgQDk52HC2XLdui/wMnESIJ/+qwuKh/BAC7e/jEuZpQxRFVbE8L2m638f+tkXdHlMERqaROd2h31cPpvZzOyeJBvhUEmuQcBfq+G4YsRQIH0XDvx/nBO4m03nFOXyLkFx4X1fZs/0i3CO506WHdgkM5wd8nA6+9S4DdNAjHvoC4WQ3A=="
|
||||
ali-public-key: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhgLRPY+3aSGRvlcivmcPnSSL9v3BXSea3uDOZpIpzydHxQ16c/A2m6kVh9LxlJJngXldOkO2Q4VS32RufZntc9fkjiiuUxDBlFPKl5x72eiQVoBX4yM7j0gtBlwQFezsIPD0SRC/uxj75+MtjDUupAQLA4gB4zgSDmWWYAIGQlgXXAQExr5k7P1dXrXJMP9SpIYn3Uaug5ifqxanoiDCmMp/sMFasjlVBDIpLOZuKgBwcX3d2FmhRdWIWR5UVy3IbtWuqTJ8vqH8j6Y2jVFLxBA7+woYc0s7npZ0kTa0yGXFw/9LGinSGshGUCBjuAoi67cW6YvODjYFHuGqsrXZvwIDAQAB"
|
||||
database:
|
||||
host: "124.223.222.61"
|
||||
port: "3306"
|
||||
username: "elf1990"
|
||||
password: "XtN1YiaqP4BxC9MEe"
|
||||
dbname: "gold-shop"
|
||||
redis:
|
||||
host: "127.0.0.1"
|
||||
port: "6379"
|
||||
password: ""
|
||||
db: 0
|
||||
jwt:
|
||||
key: "I2js2oElEo82NmRru8v73Nwm"
|
||||
issuer: "gold-shop"
|
@ -1,20 +0,0 @@
|
||||
package config
|
||||
|
||||
type Payment struct {
|
||||
BaseUrl string `yaml:"base-url"`
|
||||
ApiKey string `yaml:"api-key"`
|
||||
SignKey string `yaml:"sign-key"`
|
||||
WxPay WxPay `yaml:"wx-pay"`
|
||||
AliPay AliPay `yaml:"ali-pay"`
|
||||
}
|
||||
|
||||
type WxPay struct {
|
||||
SubAppId string `yaml:"sub-app-id"`
|
||||
SubAppSecret string `yaml:"sub-app-secret"`
|
||||
AuthRedirectUri string `yaml:"auth-redirect-uri"`
|
||||
}
|
||||
|
||||
type AliPay struct {
|
||||
SubAppId string `yaml:"sub-app-id"`
|
||||
SubPriPemFile string `yaml:"sub-pri-pem-file"`
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package config
|
||||
|
||||
type TlPay struct {
|
||||
BaseUrl string `yaml:"base-url"`
|
||||
CusID string `yaml:"cus-id"`
|
||||
AppId string `yaml:"app-id"`
|
||||
PriPemFile string `yaml:"pri-pem-file"`
|
||||
PubPemFile string `yaml:"pub-pem-file"`
|
||||
TlPubPemFile string `yaml:"tl-pub-pem-file"`
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package request
|
||||
|
||||
type TestRequest struct {
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Order struct {
|
||||
ID int
|
||||
OrderNo string
|
||||
UserID int
|
||||
Amount float64
|
||||
User User `gorm:"foreignKey:UserID;references:ID"`
|
||||
OrderProducts []OrderProduct `gorm:"foreignKey:OrderNo;references:OrderNo"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
func (Order) TableName() string {
|
||||
return "orders"
|
||||
}
|
||||
|
||||
func (o Order) MarshalJSON() ([]byte, error) {
|
||||
type Alias Order
|
||||
return json.Marshal(&struct {
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
*Alias
|
||||
}{
|
||||
CreatedAt: o.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
UpdatedAt: o.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
Alias: (*Alias)(&o),
|
||||
})
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type OrderProduct struct {
|
||||
ID uint
|
||||
OrderNo string
|
||||
UserID int
|
||||
ProductID int
|
||||
Num int
|
||||
Price float64
|
||||
Amount float64
|
||||
Order *Order `gorm:"foreignKey:OrderNo;references:OrderNo"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
func (OrderProduct) TableName() string {
|
||||
return "order_products"
|
||||
}
|
||||
|
||||
func (p OrderProduct) MarshalJSON() ([]byte, error) {
|
||||
type Alias OrderProduct
|
||||
return json.Marshal(&struct {
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
*Alias
|
||||
}{
|
||||
CreatedAt: p.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
UpdatedAt: p.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
Alias: (*Alias)(&p),
|
||||
})
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
const PaymentStatusSuccess = 1
|
||||
const PaymentStatusFailed = 2
|
||||
const PaymentStatusWait = 0
|
||||
|
||||
type Payment struct {
|
||||
ID int
|
||||
PaymentNo string
|
||||
PayOrderID string
|
||||
UserID int
|
||||
Amount float64
|
||||
Token string
|
||||
User User `gorm:"foreignKey:UserID;references:ID"`
|
||||
PayType string
|
||||
OpenID string
|
||||
ErrorMessage string
|
||||
PayerCardNo string
|
||||
PayerAccountName string
|
||||
Status int
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
func (Payment) TableName() string {
|
||||
return "payments"
|
||||
}
|
||||
|
||||
func (p Payment) MarshalJSON() ([]byte, error) {
|
||||
type Alias Payment
|
||||
return json.Marshal(&struct {
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
*Alias
|
||||
}{
|
||||
CreatedAt: p.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
UpdatedAt: p.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
Alias: (*Alias)(&p),
|
||||
})
|
||||
}
|
||||
|
||||
func (p Payment) GetStatusText() string {
|
||||
statusText := ""
|
||||
switch p.Status {
|
||||
case PaymentStatusSuccess:
|
||||
statusText = "支付成功"
|
||||
case PaymentStatusFailed:
|
||||
statusText = "支付失败"
|
||||
case PaymentStatusWait:
|
||||
statusText = "待支付"
|
||||
}
|
||||
return statusText
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type Product struct {
|
||||
ID int
|
||||
Name string
|
||||
Price float64
|
||||
Description string
|
||||
CreatedAt time.Time `json:"-"`
|
||||
UpdatedAt time.Time `json:"-"`
|
||||
}
|
||||
|
||||
func (Product) TableName() string {
|
||||
return "products"
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type UserBankCard struct {
|
||||
ID int
|
||||
UserID int
|
||||
Mobile string
|
||||
AccountName string
|
||||
AccountNo string
|
||||
IdCardNo string
|
||||
AgreeID string
|
||||
BankCode string
|
||||
BankName string
|
||||
Status int
|
||||
ErrorMessage string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time `json:"-"`
|
||||
}
|
||||
|
||||
func (UserBankCard) TableName() string {
|
||||
return "user_bank_cards"
|
||||
}
|
||||
|
||||
func (c UserBankCard) MarshalJSON() ([]byte, error) {
|
||||
type Alias UserBankCard
|
||||
return json.Marshal(&struct {
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
*Alias
|
||||
}{
|
||||
CreatedAt: c.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
UpdatedAt: c.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
Alias: (*Alias)(&c),
|
||||
})
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package request
|
||||
|
||||
type BindingPayConfirmRequest struct {
|
||||
PaymentNo string `json:"paymentNo" form:"paymentNo"`
|
||||
SmsCode string `json:"smsCode" form:"smsCode"`
|
||||
ThpInfo string `json:"thpInfo" form:"thpInfo"`
|
||||
AgreeID string `json:"agreeId" form:"agreeId"`
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package request
|
||||
|
||||
type BindingPaySmsRequest struct {
|
||||
PaymentNo string `json:"paymentNo" form:"paymentNo"`
|
||||
ThpInfo string `json:"thpInfo" form:"thpInfo"`
|
||||
AgreeID string `json:"agreeId" form:"agreeId"`
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package request
|
||||
|
||||
type CheckOutOrderRequest struct {
|
||||
Intent string `json:"intent"`
|
||||
PurchaseUnits []PurchaseUnit `json:"purchase_units"`
|
||||
ApplicationContext ApplicationContext `json:"application_context"`
|
||||
}
|
||||
|
||||
type PurchaseUnit struct {
|
||||
Amount Amount `json:"amount"`
|
||||
Description string `json:"description"`
|
||||
CustomId int `json:"custom_id"`
|
||||
}
|
||||
|
||||
type Amount struct {
|
||||
CurrencyCode string `json:"currency_code"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
type ApplicationContext struct {
|
||||
CancelUrl string `json:"cancel_url"`
|
||||
ReturnUrl string `json:"return_url"`
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package manage
|
||||
|
||||
type AddAdminRequest struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package manage
|
||||
|
||||
type LoginRequest struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package manage
|
||||
|
||||
import "gold-shop/request"
|
||||
|
||||
type OrderQueryRequest struct {
|
||||
request.PageQueryRequest
|
||||
UserID int `form:"userId"`
|
||||
Mobile string `form:"mobile"`
|
||||
OrderNo string `form:"orderNo"`
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package manage
|
||||
|
||||
import "gold-shop/request"
|
||||
|
||||
type PaymentQueryRequest struct {
|
||||
request.PageQueryRequest
|
||||
UserID int `form:"userId"`
|
||||
Mobile string `form:"mobile"`
|
||||
PaymentNo string `form:"paymentNo"`
|
||||
Status string `form:"status"`
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package manage
|
||||
|
||||
import "gold-shop/request"
|
||||
|
||||
type UserQueryRequest struct {
|
||||
request.PageQueryRequest
|
||||
Mobile string `form:"mobile"`
|
||||
Status string `form:"status"`
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package request
|
||||
|
||||
type OrderQueryRequest struct {
|
||||
PageQueryRequest
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package request
|
||||
|
||||
type OrderRequest struct {
|
||||
ProductID int `json:"productId" form:"productId"`
|
||||
Num int `json:"num" form:"num"`
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package request
|
||||
|
||||
type PageQueryRequest struct {
|
||||
Page int `form:"page"`
|
||||
PageSize int `form:"pageSize"`
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package request
|
||||
|
||||
type PaymentNotifyRequest struct {
|
||||
OrderID string `form:"orderid"`
|
||||
TradeNo string `form:"trade_no"`
|
||||
DisName string `form:"dis_name"`
|
||||
PayStatus int `form:"paystatus"`
|
||||
PayMoney float64 `form:"paymoney"`
|
||||
PriPayMoney float64 `form:"pri_paymoney"`
|
||||
OrderTime int64 `form:"order_time"`
|
||||
PayTime int64 `form:"paytime"`
|
||||
MchOrderID string `form:"mch_orderid"`
|
||||
NotifyUrl string `form:"notify_url"`
|
||||
BuyerAccount string `form:"buyer_account"`
|
||||
Attach string `form:"attach"`
|
||||
Sign string `form:"sign"`
|
||||
SignType string `form:"sign_type"`
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package request
|
||||
|
||||
type PaymentQueryRequest struct {
|
||||
PageQueryRequest
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package request
|
||||
|
||||
type PaymentRequest struct {
|
||||
OpenID string `json:"openId" form:"openId"`
|
||||
Amount float64 `json:"amount" form:"amount"`
|
||||
PayType string `json:"payType" form:"payType"`
|
||||
AgreeID string `json:"agreeId" form:"agreeId"`
|
||||
ThpInfo string `json:"thpInfo" form:"thpInfo"`
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package request
|
||||
|
||||
type TlBindingApplyRequest struct {
|
||||
IdNo string `json:"idNo" form:"idNo"`
|
||||
AcctName string `json:"acctName" form:"acctName"`
|
||||
AcctNo string `json:"acctNo" form:"acctNo"`
|
||||
AcctType string `json:"acctType" form:"acctType"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
ValidDate string `json:"validDate" form:"validDate"`
|
||||
Cvv2 string `json:"cvv2" form:"cvv2"`
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package request
|
||||
|
||||
type TlBindingConfirmRequest struct {
|
||||
IdNo string `json:"idNo" form:"idNo"`
|
||||
AcctName string `json:"acctName" form:"acctName"`
|
||||
AcctNo string `json:"acctNo" form:"acctNo"`
|
||||
AcctType string `json:"acctType" form:"acctType"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
ValidDate string `json:"validDate" form:"validDate"`
|
||||
Cvv2 string `json:"cvv2" form:"cvv2"`
|
||||
SmsCode string `json:"smsCode" form:"smsCode"`
|
||||
ThpInfo string `json:"thpInfo" form:"thpInfo"`
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package request
|
||||
|
||||
type TransferPayNotifyRequest struct {
|
||||
OutOrderID string `json:"out_orderid"`
|
||||
ApiKey string `json:"apikey"`
|
||||
PayerCardNo string `json:"payer_card_no"`
|
||||
OrderID string `json:"orderid"`
|
||||
PayerAccountName string `json:"payer_account_name"`
|
||||
OrderMoney string `json:"order_money"`
|
||||
PayeeAccountName string `json:"payee_account_name"`
|
||||
PayeeBankName string `json:"payee_bank_name"`
|
||||
PayMoney string `json:"pay_money"`
|
||||
PayTime string `json:"pay_time"`
|
||||
PayeeCardNo string `json:"payee_card_no"`
|
||||
PayStatus string `json:"pay_status"`
|
||||
AddTime string `json:"add_time"`
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package route
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"gold-shop/api/h5"
|
||||
"gold-shop/middleware"
|
||||
"gold-shop/utils/result"
|
||||
)
|
||||
|
||||
func h5RouteInit(r *gin.Engine) {
|
||||
h5Group := r.Group("/h5")
|
||||
h5Group.Use(middleware.CorsMiddleware("h5"))
|
||||
h5Group.Match([]string{"POST", "OPTIONS"}, "/login", result.Json(h5.Login))
|
||||
h5Group.Match([]string{"POST", "OPTIONS"}, "/register", result.Json(h5.Register))
|
||||
h5Group.Match([]string{"GET", "OPTIONS"}, "/get-product-info", result.Json(h5.GetProductInfo))
|
||||
h5Group.Match([]string{"POST", "OPTIONS"}, "/transfer-pay-notify", h5.TransferPayNotify)
|
||||
h5Group.Match([]string{"POST", "OPTIONS"}, "/payment-notify", h5.PaymentNotify)
|
||||
h5Group.Match([]string{"POST", "OPTIONS"}, "/binding-pay-notify", h5.BindingPayNotify)
|
||||
h5Group.Match([]string{"GET", "OPTIONS"}, "/test-gateway-pay", h5.GatewayPay)
|
||||
h5Group.Match([]string{"GET", "OPTIONS"}, "/gateway-pay", h5.GatewayPay)
|
||||
h5Group.Match([]string{"POST", "GET", "OPTIONS"}, "/gateway-pay-ret", h5.GatewayPayRet)
|
||||
|
||||
authGroup := h5Group.Group("")
|
||||
authGroup.Use(middleware.JwtMiddleware("user"))
|
||||
{
|
||||
authGroup.Match([]string{"GET", "OPTIONS"}, "/ping", result.Json(h5.Index))
|
||||
authGroup.Match([]string{"GET", "OPTIONS"}, "/error", result.Json(h5.Error))
|
||||
authGroup.Match([]string{"GET", "OPTIONS"}, "/get-user-info", result.Json(h5.GetUserInfo))
|
||||
authGroup.Match([]string{"POST", "OPTIONS"}, "/order", result.Json(h5.Order))
|
||||
authGroup.Match([]string{"POST", "OPTIONS"}, "/modify-password", result.Json(h5.ModifyPassword))
|
||||
authGroup.Match([]string{"POST", "OPTIONS"}, "/payment", result.Json(h5.Payment))
|
||||
authGroup.Match([]string{"GET", "OPTIONS"}, "/get-wx-open-id", result.Json(h5.GetWxOpenId))
|
||||
authGroup.Match([]string{"GET", "OPTIONS"}, "/get-wx-auth-url", result.Json(h5.GetWxAuthUrl))
|
||||
authGroup.Match([]string{"GET", "OPTIONS"}, "/get-ali-open-id", result.Json(h5.GetAliOpenId))
|
||||
authGroup.Match([]string{"GET", "OPTIONS"}, "/get-orders", result.Json(h5.GetOrders))
|
||||
authGroup.Match([]string{"GET", "OPTIONS"}, "/get-payments", result.Json(h5.GetPayments))
|
||||
authGroup.Match([]string{"GET", "OPTIONS"}, "/get-user-data", result.Json(h5.GetUserData))
|
||||
authGroup.Match([]string{"POST", "OPTIONS"}, "/save-alipay-account", result.Json(h5.SaveAlipayAccount))
|
||||
authGroup.Match([]string{"POST", "OPTIONS"}, "/tl-binding-apply", result.Json(h5.TlBindingApply))
|
||||
authGroup.Match([]string{"POST", "OPTIONS"}, "/tl-binding-confirm", result.Json(h5.TlBindingConfirm))
|
||||
authGroup.Match([]string{"GET", "OPTIONS"}, "/get-user-bank-card", result.Json(h5.GetUserBankCard))
|
||||
authGroup.Match([]string{"POST", "OPTIONS"}, "/binding-pay-confirm", result.Json(h5.BindingPayConfirm))
|
||||
authGroup.Match([]string{"POST", "OPTIONS"}, "/binding-pay-sms", result.Json(h5.BindingPaySms))
|
||||
authGroup.Match([]string{"POST", "OPTIONS"}, "/gateway-pay-apply", result.Json(h5.GatewayPayApply))
|
||||
authGroup.Match([]string{"POST", "OPTIONS"}, "/bank-card-unbind", result.Json(h5.BankCardUnbind))
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package route
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"gold-shop/api/manage"
|
||||
"gold-shop/middleware"
|
||||
"gold-shop/utils/result"
|
||||
)
|
||||
|
||||
func adminRouteInit(r *gin.Engine) {
|
||||
manageGroup := r.Group("/manage")
|
||||
manageGroup.Use(middleware.CorsMiddleware("manage"))
|
||||
manageGroup.Match([]string{"POST", "OPTIONS"}, "/login", result.Json(manage.Login))
|
||||
manageGroup.GET("/download", manage.DownloadUsers)
|
||||
|
||||
authGroup := manageGroup.Group("")
|
||||
authGroup.Use(middleware.JwtMiddleware("admin"))
|
||||
{
|
||||
authGroup.Match([]string{"GET", "OPTIONS"}, "/get-admin-info", result.Json(manage.GetAdminInfo))
|
||||
authGroup.Match([]string{"POST", "OPTIONS"}, "/logout", result.Json(manage.Logout))
|
||||
authGroup.Match([]string{"POST", "OPTIONS"}, "/add-admin", result.Json(manage.AddAdmin))
|
||||
authGroup.Match([]string{"GET", "OPTIONS"}, "/get-users", result.Json(manage.GetUsers))
|
||||
authGroup.Match([]string{"GET", "OPTIONS"}, "/download-users", manage.DownloadUsers)
|
||||
authGroup.Match([]string{"GET", "OPTIONS"}, "/get-orders", result.Json(manage.GetOrders))
|
||||
authGroup.Match([]string{"GET", "OPTIONS"}, "/download-orders", manage.DownloadOrders)
|
||||
authGroup.Match([]string{"GET", "OPTIONS"}, "/get-payments", result.Json(manage.GetPayments))
|
||||
authGroup.Match([]string{"GET", "OPTIONS"}, "/download-payments", manage.DownloadPayments)
|
||||
}
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
package route
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Initial(r *gin.Engine) {
|
||||
r.Static("/asset", "./asset")
|
||||
h5RouteInit(r)
|
||||
adminRouteInit(r)
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func h5RouteInit(r *gin.Engine) {
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func adminRouteInit(r *gin.Engine) {
|
||||
}
|
@ -1,65 +1,12 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
e "errors"
|
||||
"gold-shop/errors"
|
||||
"gold-shop/global"
|
||||
"gold-shop/model"
|
||||
"gold-shop/utils"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
import "insure/model"
|
||||
|
||||
var AdminService = adminService{}
|
||||
|
||||
type adminService struct {
|
||||
}
|
||||
|
||||
func (adminService) Login(username string, password string) (string, error) {
|
||||
admin := &model.Admin{}
|
||||
err := global.DB.Where("username", username).First(admin).Error
|
||||
if e.Is(err, gorm.ErrRecordNotFound) {
|
||||
return "", errors.NewBusinessError("账号或密码错误")
|
||||
}
|
||||
if utils.PasswordVerify(password, admin.PasswordHash) {
|
||||
return utils.GenerateToken(admin.ID, "admin")
|
||||
}
|
||||
return "", errors.NewBusinessError("账号或密码错误")
|
||||
}
|
||||
|
||||
func (adminService) Add(username string, password string) error {
|
||||
admin := &model.Admin{}
|
||||
err := global.DB.Where("username", username).First(admin).Error
|
||||
if err == nil {
|
||||
return errors.NewBusinessError("账号已存在")
|
||||
}
|
||||
admin.Username = username
|
||||
passwordHash, _ := utils.PasswordHash(password)
|
||||
admin.PasswordHash = passwordHash
|
||||
return global.DB.Save(admin).Error
|
||||
}
|
||||
|
||||
func (adminService) ModifyPassword(password string, oldPassword string, admin *model.Admin) error {
|
||||
if !utils.PasswordVerify(oldPassword, admin.PasswordHash) {
|
||||
return errors.NewBusinessError("旧密码错误")
|
||||
}
|
||||
passwordHash, _ := utils.PasswordHash(password)
|
||||
admin.PasswordHash = passwordHash
|
||||
return global.DB.Save(admin).Error
|
||||
}
|
||||
|
||||
func (adminService) ResetPassword(adminID int, password string) error {
|
||||
admin := &model.Admin{}
|
||||
err := global.DB.Where("id", adminID).First(admin).Error
|
||||
if e.Is(err, gorm.ErrRecordNotFound) {
|
||||
return errors.NewBusinessError("账号不存在")
|
||||
}
|
||||
passwordHash, _ := utils.PasswordHash(password)
|
||||
admin.PasswordHash = passwordHash
|
||||
return global.DB.Save(admin).Error
|
||||
}
|
||||
|
||||
func (adminService) GetAdminInfo(adminID int) *model.Admin {
|
||||
admin := &model.Admin{}
|
||||
global.DB.Where("id", adminID).First(admin)
|
||||
return admin
|
||||
func (adminService) GetInfo(id int) *model.Admin {
|
||||
return &model.Admin{}
|
||||
}
|
||||
|
@ -1,136 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
e "errors"
|
||||
"github.com/xuri/excelize/v2"
|
||||
"gold-shop/errors"
|
||||
"gold-shop/global"
|
||||
"gold-shop/model"
|
||||
"gold-shop/request"
|
||||
"gold-shop/request/manage"
|
||||
"gold-shop/utils"
|
||||
"gold-shop/utils/excel"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
var OrderService = orderService{}
|
||||
|
||||
type orderService struct {
|
||||
}
|
||||
|
||||
func (orderService) Order(orderRequest request.OrderRequest, user *model.User) (*model.Order, error) {
|
||||
product := &model.Product{}
|
||||
err := global.DB.Where("id", orderRequest.ProductID).First(product).Error
|
||||
if e.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errors.NewBusinessError("商品不存在")
|
||||
}
|
||||
totalAmount := float64(orderRequest.Num) * product.Price
|
||||
if user.Balance < totalAmount {
|
||||
return nil, errors.NewBusinessError("账号余额不足")
|
||||
}
|
||||
|
||||
orderNo := utils.GenerateNo("order")
|
||||
|
||||
tx := global.DB.Begin()
|
||||
order := model.Order{}
|
||||
order.OrderNo = orderNo
|
||||
order.Amount = totalAmount
|
||||
order.UserID = user.ID
|
||||
err = global.DB.Save(&order).Error
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return nil, errors.NewBusinessError("保存数据失败")
|
||||
}
|
||||
|
||||
orderProduct := model.OrderProduct{}
|
||||
orderProduct.ProductID = orderRequest.ProductID
|
||||
orderProduct.OrderNo = orderNo
|
||||
orderProduct.Price = product.Price
|
||||
orderProduct.Amount = totalAmount
|
||||
orderProduct.Num = orderRequest.Num
|
||||
err = global.DB.Save(&orderProduct).Error
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return nil, errors.NewBusinessError("保存数据失败")
|
||||
}
|
||||
|
||||
global.DB.Model(user).Update("balance", gorm.Expr("balance - ?", totalAmount))
|
||||
tx.Commit()
|
||||
|
||||
return &order, nil
|
||||
}
|
||||
|
||||
func (orderService) GetUserOrders(userID, page, pageSize int) ([]model.Order, int64) {
|
||||
orders := make([]model.Order, pageSize)
|
||||
offset := (page - 1) * pageSize
|
||||
var total int64
|
||||
global.DB.Where("user_id", userID).Preload("OrderProducts").Offset(offset).Limit(pageSize).Find(&orders)
|
||||
global.DB.Model(&model.Order{}).Where("user_id", userID).Count(&total)
|
||||
return orders, total
|
||||
}
|
||||
|
||||
func (s *orderService) buildQuery(req manage.OrderQueryRequest) *gorm.DB {
|
||||
tx := global.DB
|
||||
if req.Mobile != "" {
|
||||
var userIds []int
|
||||
global.DB.Model(&model.User{}).Where("mobile", req.Mobile).Pluck("id", &userIds)
|
||||
tx = tx.Where("user_id", userIds)
|
||||
}
|
||||
if req.OrderNo != "" {
|
||||
tx = tx.Where("order_no", req.OrderNo)
|
||||
}
|
||||
if req.UserID != 0 {
|
||||
tx = tx.Where("user_id", req.UserID)
|
||||
}
|
||||
return tx
|
||||
}
|
||||
|
||||
func (s *orderService) GetOrders(req manage.OrderQueryRequest) ([]model.Order, int64) {
|
||||
orders := make([]model.Order, req.PageSize)
|
||||
offset := (req.Page - 1) * req.PageSize
|
||||
var total int64
|
||||
tx := s.buildQuery(req)
|
||||
tx.Preload("OrderProducts").Preload("User").Order("id desc").Offset(offset).Limit(req.PageSize).Find(&orders)
|
||||
tx.Model(&model.Order{}).Count(&total)
|
||||
return orders, total
|
||||
}
|
||||
|
||||
func (s *orderService) GenerateOrdersExcel(req manage.OrderQueryRequest) *excelize.File {
|
||||
pageSize := 200
|
||||
lastID := 0
|
||||
tx := s.buildQuery(req)
|
||||
|
||||
f := excel.NewFile()
|
||||
headers := []string{"订单号", "用户手机号", "购买份数", "订单总金额", "下单时间"}
|
||||
excel.SetSimpleHeaders(headers, "Sheet1", f)
|
||||
for {
|
||||
orders := make([]model.Order, pageSize)
|
||||
tx.Preload("OrderProducts").Preload("User").Where("id > ?", lastID).Limit(pageSize).Find(&orders)
|
||||
count := len(orders)
|
||||
if count == 0 {
|
||||
break
|
||||
}
|
||||
s.buildOrdersExcel(orders, "Sheet1", f)
|
||||
lastIndex := count - 1
|
||||
lastID = orders[lastIndex].ID
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
func (orderService) buildOrdersExcel(orders []model.Order, sheet string, f *excelize.File) {
|
||||
row := 2
|
||||
for _, order := range orders {
|
||||
col := 0
|
||||
num := 0
|
||||
for _, orderProduct := range order.OrderProducts {
|
||||
num += orderProduct.Num
|
||||
}
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), order.OrderNo)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), order.User.Mobile)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), num)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), order.Amount)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), order.CreatedAt.Format(time.DateTime))
|
||||
row++
|
||||
}
|
||||
}
|
@ -1,441 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
e "errors"
|
||||
"fmt"
|
||||
"github.com/xuri/excelize/v2"
|
||||
"gold-shop/errors"
|
||||
"gold-shop/global"
|
||||
"gold-shop/model"
|
||||
"gold-shop/request"
|
||||
"gold-shop/request/manage"
|
||||
"gold-shop/utils"
|
||||
"gold-shop/utils/excel"
|
||||
"gold-shop/utils/payment"
|
||||
"gold-shop/utils/result"
|
||||
"gold-shop/utils/tlpay"
|
||||
"gold-shop/utils/tlpay/notify"
|
||||
"gold-shop/utils/tlpay/param"
|
||||
"gorm.io/gorm"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
var PaymentService = paymentService{}
|
||||
|
||||
type paymentService struct {
|
||||
}
|
||||
|
||||
func (paymentService) GetUserPayments(userID, page, pageSize int) ([]model.Payment, int64) {
|
||||
payments := make([]model.Payment, pageSize)
|
||||
offset := (page - 1) * pageSize
|
||||
var total int64
|
||||
global.DB.Where("user_id", userID).Order("id desc").Offset(offset).Limit(pageSize).Find(&payments)
|
||||
global.DB.Model(&model.Payment{}).Where("user_id", userID).Count(&total)
|
||||
return payments, total
|
||||
}
|
||||
|
||||
func (s paymentService) Payment(userID int, paymentRequest request.PaymentRequest) (result.Data, error) {
|
||||
p, err := s.createPayment(userID, paymentRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data := result.Data{}
|
||||
if paymentRequest.PayType == "wxgzh" {
|
||||
data, err = s.wxPayment(paymentRequest, p.PaymentNo)
|
||||
} else if paymentRequest.PayType == "alishh" {
|
||||
data, err = s.aliPayment(paymentRequest, p.PaymentNo)
|
||||
} else if paymentRequest.PayType == "transfer" {
|
||||
data, err = s.transferPayment(paymentRequest, p)
|
||||
} else if paymentRequest.PayType == "binding" {
|
||||
data, err = s.bindingPayment(paymentRequest, p)
|
||||
} else if paymentRequest.PayType == "gateway" {
|
||||
data, err = s.getGatewayPayUrl(p)
|
||||
} else {
|
||||
err = errors.NewBusinessError("payType参数错误")
|
||||
}
|
||||
if err != nil {
|
||||
p.Status = 2
|
||||
p.ErrorMessage = err.Error()
|
||||
global.DB.Save(p)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
p.PayOrderID = data["orderId"].(string)
|
||||
global.DB.Save(p)
|
||||
fmt.Println(data)
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (s paymentService) wxPayment(paymentRequest request.PaymentRequest, orderID string) (result.Data, error) {
|
||||
param := payment.WxPayParam{}
|
||||
param.Remark = "payment"
|
||||
param.OrderId = orderID
|
||||
param.OpenId = paymentRequest.OpenID
|
||||
param.Amount = paymentRequest.Amount
|
||||
param.NotifyUrl = "http://api.wrtcjt.com/h5/payment-notify"
|
||||
res, err := payment.PayApi.WxPay(param)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if res.Status != payment.Success {
|
||||
return nil, errors.NewBusinessError(res.Message)
|
||||
}
|
||||
|
||||
data := result.Data{
|
||||
"orderId": res.OrderID,
|
||||
"paySign": res.PaySign,
|
||||
"package": res.Package,
|
||||
"signType": res.PaySignType,
|
||||
"nonceStr": res.NonceStr,
|
||||
"appId": res.AppId,
|
||||
"timeStamp": res.Timestamp,
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (s paymentService) aliPayment(paymentRequest request.PaymentRequest, orderID string) (result.Data, error) {
|
||||
param := payment.AliPayParam{}
|
||||
param.Remark = "payment"
|
||||
param.OrderId = orderID
|
||||
param.BuyerId = paymentRequest.OpenID
|
||||
param.Amount = paymentRequest.Amount
|
||||
param.NotifyUrl = "http://api.wrtcjt.com/h5/payment-notify"
|
||||
res, err := payment.PayApi.AliPay(param)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if res.Status != payment.Success {
|
||||
return nil, errors.NewBusinessError(res.Message)
|
||||
}
|
||||
|
||||
data := result.Data{
|
||||
"orderId": res.OrderID,
|
||||
"tradeNo": res.TradeNo,
|
||||
"paymentNo": orderID,
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (s paymentService) transferPayment(paymentRequest request.PaymentRequest, p *model.Payment) (result.Data, error) {
|
||||
param := payment.TransferPayParam{}
|
||||
param.Remark = "payment"
|
||||
param.OrderId = utils.GenerateNo("payment")
|
||||
param.Amount = paymentRequest.Amount
|
||||
param.NotifyUrl = ""
|
||||
res, err := payment.PayApi.TransferPay(param)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if res.Status != payment.Success {
|
||||
return nil, errors.NewBusinessError(res.Message)
|
||||
}
|
||||
|
||||
data := result.Data{
|
||||
"payeeAccountName": res.PayeeAccountName,
|
||||
"payeeBankName": res.PayeeBankName,
|
||||
"payeeCardNo": res.PayeeCardNo,
|
||||
"orderID": res.OrderID,
|
||||
"paymentNo": p.PaymentNo,
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (s paymentService) bindingPayment(paymentRequest request.PaymentRequest, p *model.Payment) (result.Data, error) {
|
||||
payParam := param.PayApplyAgreeParam{}
|
||||
payParam.Amount = strconv.FormatFloat(paymentRequest.Amount*100, 'f', 0, 64)
|
||||
payParam.AgreeID = paymentRequest.AgreeID
|
||||
payParam.ReqSn = p.PaymentNo
|
||||
payParam.Currency = "CNY"
|
||||
payParam.Subject = "充值"
|
||||
payParam.TrxReserve = "充值"
|
||||
payParam.NotifyUrl = "http://api.wrtcjt.com/h5/binding-pay-notify"
|
||||
res, err := tlpay.TLPay.PayApplyAgree(payParam)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if res.RetCode != "SUCCESS" {
|
||||
return nil, errors.NewBusinessError(res.RetMsg)
|
||||
}
|
||||
if res.TrxStatus != "1999" {
|
||||
return nil, errors.NewBusinessError(res.ErrMsg)
|
||||
}
|
||||
|
||||
data := result.Data{
|
||||
"paymentNo": p.PaymentNo,
|
||||
"orderId": res.TrxID,
|
||||
"thpInfo": base64.StdEncoding.EncodeToString([]byte(res.ThpInfo)),
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (s paymentService) ConfirmBindingPayment(req request.BindingPayConfirmRequest, user *model.User) (result.Data, error) {
|
||||
pm := &model.Payment{}
|
||||
err := global.DB.Where("user_id", user.ID).Where("payment_no", req.PaymentNo).Where("status", 0).First(&pm).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
thpInfo, err := base64.StdEncoding.DecodeString(req.ThpInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
payParam := param.PayAgreeConfirmParam{}
|
||||
payParam.AgreeID = req.AgreeID
|
||||
payParam.ThpInfo = string(thpInfo)
|
||||
payParam.ReqSn = req.PaymentNo
|
||||
payParam.SmsCode = req.SmsCode
|
||||
res, err := tlpay.TLPay.PayAgreeConfirm(payParam)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if res.RetCode != "SUCCESS" {
|
||||
return nil, errors.NewBusinessError(res.RetMsg)
|
||||
}
|
||||
|
||||
if res.TrxStatus != "0000" {
|
||||
return nil, errors.NewBusinessError(res.ErrMsg)
|
||||
}
|
||||
|
||||
data := result.Data{
|
||||
"paymentNo": pm.PaymentNo,
|
||||
"orderId": res.TrxID,
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (s paymentService) SmsBindingPayment(req request.BindingPaySmsRequest, user *model.User) (result.Data, error) {
|
||||
pm := &model.Payment{}
|
||||
err := global.DB.Where("user_id", user.ID).Where("payment_no", req.PaymentNo).Where("status", 0).First(&pm).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
thpInfo, err := base64.StdEncoding.DecodeString(req.ThpInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
smsParam := param.PaySmsAgreeParam{}
|
||||
smsParam.AgreeID = req.AgreeID
|
||||
smsParam.ThpInfo = string(thpInfo)
|
||||
smsParam.OrderID = req.PaymentNo
|
||||
res, err := tlpay.TLPay.PaySmsAgree(smsParam)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if res.RetCode != "SUCCESS" {
|
||||
return nil, errors.NewBusinessError(res.RetMsg)
|
||||
}
|
||||
|
||||
data := result.Data{
|
||||
"paymentNo": pm.PaymentNo,
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (paymentService) createPayment(userID int, paymentRequest request.PaymentRequest) (*model.Payment, error) {
|
||||
p := model.Payment{}
|
||||
p.PaymentNo = utils.GenerateNo("payment")
|
||||
p.Amount = paymentRequest.Amount
|
||||
p.OpenID = paymentRequest.OpenID
|
||||
p.PayType = paymentRequest.PayType
|
||||
p.Status = 0
|
||||
p.UserID = userID
|
||||
err := global.DB.Save(&p).Error
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("保存数据失败")
|
||||
}
|
||||
return &p, nil
|
||||
}
|
||||
|
||||
func (s *paymentService) buildQuery(req manage.PaymentQueryRequest) *gorm.DB {
|
||||
tx := global.DB
|
||||
if req.Mobile != "" {
|
||||
var userIds []int
|
||||
global.DB.Model(&model.User{}).Where("mobile", req.Mobile).Pluck("id", &userIds)
|
||||
tx = tx.Where("user_id", userIds)
|
||||
}
|
||||
if req.PaymentNo != "" {
|
||||
tx = tx.Where("payment_no", req.PaymentNo)
|
||||
}
|
||||
if req.Status != "" {
|
||||
tx = tx.Where("status", req.Status)
|
||||
}
|
||||
if req.UserID != 0 {
|
||||
tx = tx.Where("user_id", req.UserID)
|
||||
}
|
||||
return tx
|
||||
}
|
||||
|
||||
func (s *paymentService) GetPayments(req manage.PaymentQueryRequest) ([]model.Payment, int64) {
|
||||
payments := make([]model.Payment, req.PageSize)
|
||||
offset := (req.Page - 1) * req.PageSize
|
||||
var total int64
|
||||
tx := s.buildQuery(req)
|
||||
tx.Preload("User").Order("id desc").Offset(offset).Limit(req.PageSize).Find(&payments)
|
||||
tx.Model(&model.Order{}).Count(&total)
|
||||
return payments, total
|
||||
}
|
||||
|
||||
func (s *paymentService) GeneratePaymentsExcel(req manage.PaymentQueryRequest) *excelize.File {
|
||||
pageSize := 200
|
||||
lastID := 0
|
||||
tx := s.buildQuery(req)
|
||||
f := excel.NewFile()
|
||||
headers := []string{"支付订单号", "用户手机号", "金额", "支付状态", "支付时间"}
|
||||
excel.SetSimpleHeaders(headers, "Sheet1", f)
|
||||
for {
|
||||
payments := make([]model.Payment, pageSize)
|
||||
tx.Preload("User").Where("id > ?", lastID).Limit(pageSize).Find(&payments)
|
||||
count := len(payments)
|
||||
if count == 0 {
|
||||
break
|
||||
}
|
||||
s.buildPaymentsExcel(payments, "Sheet1", f)
|
||||
lastIndex := count - 1
|
||||
lastID = payments[lastIndex].ID
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
func (paymentService) buildPaymentsExcel(payments []model.Payment, sheet string, f *excelize.File) {
|
||||
row := 2
|
||||
for _, p := range payments {
|
||||
col := 0
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), p.PaymentNo)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), p.User.Mobile)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), p.Amount)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), p.GetStatusText())
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), p.CreatedAt.Format(time.DateTime))
|
||||
row++
|
||||
}
|
||||
}
|
||||
|
||||
func (s paymentService) AfterTransferPayNotify(req request.TransferPayNotifyRequest) error {
|
||||
pm := &model.Payment{}
|
||||
err := global.DB.Where("payment_no", req.OutOrderID).Where("status", 0).First(&pm).Error
|
||||
if err != nil && e.Is(err, gorm.ErrRecordNotFound) {
|
||||
return errors.NewBusinessError("记录不存在")
|
||||
}
|
||||
|
||||
user := model.User{}
|
||||
global.DB.Model(&model.User{}).Where("id", pm.UserID).Find(&user)
|
||||
|
||||
if req.PayStatus == "1" {
|
||||
pm.Status = 1
|
||||
pm.PayerCardNo = req.PayerCardNo
|
||||
pm.PayerAccountName = req.PayerAccountName
|
||||
global.DB.Save(&user)
|
||||
} else {
|
||||
pm.Status = 2
|
||||
}
|
||||
|
||||
err = global.DB.Save(&pm).Error
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (s paymentService) AfterPaymentNotify(req request.PaymentNotifyRequest) error {
|
||||
pm := &model.Payment{}
|
||||
err := global.DB.Where("payment_no", req.MchOrderID).Where("status", 0).First(&pm).Error
|
||||
if err != nil && e.Is(err, gorm.ErrRecordNotFound) {
|
||||
return errors.NewBusinessError("记录不存在")
|
||||
}
|
||||
|
||||
user := model.User{}
|
||||
global.DB.Model(&model.User{}).Where("id", pm.UserID).Find(&user)
|
||||
|
||||
if req.PayStatus == 1 {
|
||||
pm.Status = 1
|
||||
global.DB.Model(&user).UpdateColumn("balance", gorm.Expr("balance + ?", pm.Amount))
|
||||
} else {
|
||||
pm.Status = 2
|
||||
}
|
||||
|
||||
err = global.DB.Save(&pm).Error
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (s paymentService) AfterBindingPayNotify(req notify.PayAgreeNotify) error {
|
||||
pm := &model.Payment{}
|
||||
err := global.DB.Where("payment_no", req.CusOrderID).Where("status", 0).First(&pm).Error
|
||||
if err != nil && e.Is(err, gorm.ErrRecordNotFound) {
|
||||
return errors.NewBusinessError("记录不存在")
|
||||
}
|
||||
|
||||
user := model.User{}
|
||||
global.DB.Model(&model.User{}).Where("id", pm.UserID).Find(&user)
|
||||
|
||||
if req.TrxStatus == "0000" {
|
||||
pm.Status = 1
|
||||
global.DB.Model(&user).UpdateColumn("balance", gorm.Expr("balance + ?", pm.Amount))
|
||||
} else {
|
||||
pm.Status = 2
|
||||
}
|
||||
|
||||
err = global.DB.Save(&pm).Error
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (s paymentService) GatewayPay(token string) (string, error) {
|
||||
pm := &model.Payment{}
|
||||
err := global.DB.Where("token", token).Where("status", 0).First(&pm).Error
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
p := param.GatewayPayParam{}
|
||||
p.OrderID = pm.PaymentNo
|
||||
p.PayType = "B2B,B2C"
|
||||
p.TrxAmt = strconv.FormatFloat(pm.Amount*100, 'f', 0, 64)
|
||||
p.LimitPay = "no_credit"
|
||||
p.RetUrl = "http://api.wrtcjt.com/h5/gateway-pay-ret"
|
||||
//p.RetUrl = "https://www.baidu.com"
|
||||
p.NotifyUrl = "http://api.wrtcjt.com/h5/binding-pay-notify"
|
||||
p.GoodsID = "1"
|
||||
p.GoodsInf = "充值"
|
||||
p.Charset = "UTF-8"
|
||||
|
||||
str := tlpay.TLPay.GatewayPay(p)
|
||||
return str, nil
|
||||
}
|
||||
|
||||
func (s paymentService) GatewayPayRet(ret notify.GatewayPayRet) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (s paymentService) GatewayPayApply(userID int, paymentRequest request.PaymentRequest) (result.Data, error) {
|
||||
pm, err := s.createPayment(userID, paymentRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s.getGatewayPayUrl(pm)
|
||||
}
|
||||
|
||||
func (s paymentService) getGatewayPayUrl(pm *model.Payment) (result.Data, error) {
|
||||
token := utils.Md5(pm.PaymentNo + strconv.Itoa(pm.UserID) + "_gateway")
|
||||
pm.Token = token
|
||||
err := global.DB.Save(pm).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data := result.Data{"url": "http://api.wrtcjt.com/h5/gateway-pay?token=" + token, "orderId": ""}
|
||||
return data, nil
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
e "errors"
|
||||
"gold-shop/errors"
|
||||
"gold-shop/global"
|
||||
"gold-shop/model"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var ProductService = productService{}
|
||||
|
||||
type productService struct {
|
||||
}
|
||||
|
||||
func (productService) GetProductInfo(productID int) (*model.Product, error) {
|
||||
product := &model.Product{}
|
||||
err := global.DB.Where("id", productID).First(product).Error
|
||||
if e.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errors.NewBusinessError("商品不存在")
|
||||
}
|
||||
return product, nil
|
||||
}
|
@ -1,306 +1,12 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
e "errors"
|
||||
"fmt"
|
||||
"github.com/xuri/excelize/v2"
|
||||
"gold-shop/errors"
|
||||
"gold-shop/global"
|
||||
"gold-shop/model"
|
||||
"gold-shop/request"
|
||||
"gold-shop/request/manage"
|
||||
"gold-shop/utils"
|
||||
"gold-shop/utils/excel"
|
||||
"gold-shop/utils/result"
|
||||
"gold-shop/utils/tlpay"
|
||||
"gold-shop/utils/tlpay/param"
|
||||
"gorm.io/gorm"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
import "insure/model"
|
||||
|
||||
var UserService = userService{}
|
||||
|
||||
type userService struct {
|
||||
}
|
||||
|
||||
func (userService) Login(mobile string, password string) (string, error) {
|
||||
user := &model.User{}
|
||||
err := global.DB.Where("mobile", mobile).First(user).Error
|
||||
if e.Is(err, gorm.ErrRecordNotFound) {
|
||||
return "", errors.NewBusinessError("手机号或密码错误")
|
||||
}
|
||||
if utils.PasswordVerify(password, user.PasswordHash) {
|
||||
return utils.GenerateToken(user.ID, "user")
|
||||
}
|
||||
return "", errors.NewBusinessError("手机号或密码错误")
|
||||
}
|
||||
|
||||
func (userService) Register(mobile string, password string) error {
|
||||
user := &model.User{}
|
||||
err := global.DB.Where("mobile", mobile).First(user).Error
|
||||
if err == nil {
|
||||
return errors.NewBusinessError("手机号已注册")
|
||||
}
|
||||
user.Mobile = mobile
|
||||
passwordHash, _ := utils.PasswordHash(password)
|
||||
user.PasswordHash = passwordHash
|
||||
user.Status = 1
|
||||
return global.DB.Save(user).Error
|
||||
}
|
||||
|
||||
func (userService) GetUserInfo(userId int) *model.User {
|
||||
user := &model.User{}
|
||||
global.DB.Where("id", userId).First(user)
|
||||
return user
|
||||
}
|
||||
|
||||
func (userService) ModifyPassword(password string, oldPassword string, user *model.User) error {
|
||||
if !utils.PasswordVerify(oldPassword, user.PasswordHash) {
|
||||
return errors.NewBusinessError("旧密码错误")
|
||||
}
|
||||
passwordHash, _ := utils.PasswordHash(password)
|
||||
user.PasswordHash = passwordHash
|
||||
return global.DB.Save(user).Error
|
||||
}
|
||||
|
||||
func (userService) GetUserData(user *model.User) result.Data {
|
||||
var orderCount int64
|
||||
global.DB.Model(&model.Order{}).Where("user_id", user.ID).Count(&orderCount)
|
||||
data := result.Data{
|
||||
"orderCount": orderCount,
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
func (s *userService) GetUsers(req manage.UserQueryRequest) ([]model.User, int64) {
|
||||
users := make([]model.User, req.PageSize)
|
||||
offset := (req.Page - 1) * req.PageSize
|
||||
var total int64
|
||||
tx := s.buildQuery(req)
|
||||
tx.Order("id desc").Offset(offset).Limit(req.PageSize).Find(&users)
|
||||
tx.Model(&model.User{}).Count(&total)
|
||||
return users, total
|
||||
}
|
||||
|
||||
func (userService) SaveAlipayAccount(alipayAccount string, user *model.User) error {
|
||||
err := global.DB.Model(&model.User{}).Where("id", user.ID).Update("alipay_account", alipayAccount).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *userService) buildQuery(req manage.UserQueryRequest) *gorm.DB {
|
||||
tx := global.DB
|
||||
if req.Mobile != "" {
|
||||
tx = tx.Where("mobile", req.Mobile)
|
||||
}
|
||||
if req.Status != "" {
|
||||
tx = tx.Where("status", req.Status)
|
||||
}
|
||||
return tx
|
||||
}
|
||||
|
||||
func (s *userService) GenerateUsersExcel(req manage.UserQueryRequest) *excelize.File {
|
||||
pageSize := 200
|
||||
lastID := 0
|
||||
tx := s.buildQuery(req)
|
||||
f := excel.NewFile()
|
||||
headers := []string{"用户ID", "手机号", "支付宝账号", "账户余额", "用户状态", "注册时间"}
|
||||
excel.SetSimpleHeaders(headers, "Sheet1", f)
|
||||
for {
|
||||
users := make([]model.User, pageSize)
|
||||
tx.Where("id > ?", lastID).Limit(pageSize).Find(&users)
|
||||
count := len(users)
|
||||
if count == 0 {
|
||||
break
|
||||
}
|
||||
s.buildUserListExcel(users, "Sheet1", f)
|
||||
lastIndex := count - 1
|
||||
lastID = users[lastIndex].ID
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
func (userService) buildUserListExcel(users []model.User, sheet string, f *excelize.File) {
|
||||
row := 2
|
||||
for _, user := range users {
|
||||
col := 0
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), user.ID)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), user.Mobile)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), user.AlipayAccount)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), user.Balance)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), user.GetStatusText())
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), user.CreatedAt.Format(time.DateTime))
|
||||
row++
|
||||
}
|
||||
}
|
||||
|
||||
func (s *userService) TlBindingApply(req request.TlBindingApplyRequest, user *model.User) (string, error) {
|
||||
thpInfo, err := s.doTlBindingApply(req, user)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
_, err = s.createBankCard(req, user)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return thpInfo, nil
|
||||
}
|
||||
|
||||
func (s *userService) doTlBindingApply(req request.TlBindingApplyRequest, user *model.User) (string, error) {
|
||||
acctType := "00"
|
||||
if req.AcctType != "" {
|
||||
acctType = req.AcctType
|
||||
}
|
||||
p := param.AgreeApplyParam{}
|
||||
p.Mobile = req.Mobile
|
||||
p.IdNo = req.IdNo
|
||||
p.Cvv2 = req.Cvv2
|
||||
p.AcctNo = req.AcctNo
|
||||
p.AcctName = req.AcctName
|
||||
p.ValidDate = req.ValidDate
|
||||
p.MerUserID = strconv.Itoa(user.ID)
|
||||
p.IdType = "0"
|
||||
p.AcctType = acctType
|
||||
p.ReqIp = "127.0.0.1"
|
||||
p.Version = "11"
|
||||
|
||||
r, err := tlpay.TLPay.AgreeApply(p)
|
||||
fmt.Println(r)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if r.RetCode != "SUCCESS" {
|
||||
return "", errors.NewBusinessError(r.RetMsg)
|
||||
}
|
||||
if r.TrxStatus != "1999" {
|
||||
return "", errors.NewBusinessError(r.ErrMsg)
|
||||
}
|
||||
return base64.StdEncoding.EncodeToString([]byte(r.ThpInfo)), nil
|
||||
}
|
||||
|
||||
func (userService) createBankCard(req request.TlBindingApplyRequest, user *model.User) (*model.UserBankCard, error) {
|
||||
c := model.UserBankCard{}
|
||||
err := global.DB.Where("user_id", user.ID).Where("account_no", req.AcctNo).First(&c).Error
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
if err == nil && c.Status == 1 {
|
||||
return nil, errors.NewBusinessError("该卡号已绑定")
|
||||
}
|
||||
c.AccountName = req.AcctName
|
||||
c.IdCardNo = req.IdNo
|
||||
c.AccountNo = req.AcctNo
|
||||
c.Mobile = req.Mobile
|
||||
c.Status = 0
|
||||
c.UserID = user.ID
|
||||
err = global.DB.Save(&c).Error
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("保存数据失败")
|
||||
}
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
func (s *userService) TlBindingConfirm(req request.TlBindingConfirmRequest, user *model.User) (result.Data, error) {
|
||||
c := model.UserBankCard{}
|
||||
err := global.DB.Where("user_id", user.ID).Where("account_no", req.AcctNo).First(&c).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data, err := s.doTlBindingConfirm(req, user)
|
||||
if err != nil {
|
||||
c.Status = 2
|
||||
c.ErrorMessage = err.Error()
|
||||
global.DB.Save(&c)
|
||||
return nil, err
|
||||
}
|
||||
c.AgreeID = data["agreeId"].(string)
|
||||
c.Status = 1
|
||||
c.ErrorMessage = "成功"
|
||||
c.BankName = data["bankName"].(string)
|
||||
c.BankCode = data["bankCode"].(string)
|
||||
global.DB.Save(&c)
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (userService) doTlBindingConfirm(req request.TlBindingConfirmRequest, user *model.User) (result.Data, error) {
|
||||
acctType := "00"
|
||||
if req.AcctType != "" {
|
||||
acctType = req.AcctType
|
||||
}
|
||||
thpInfo, err := base64.StdEncoding.DecodeString(req.ThpInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p := param.AgreeConfirmParam{}
|
||||
p.Mobile = req.Mobile
|
||||
p.IdNo = req.IdNo
|
||||
p.Cvv2 = req.Cvv2
|
||||
p.AcctNo = req.AcctNo
|
||||
p.AcctName = req.AcctName
|
||||
p.SmsCode = req.SmsCode
|
||||
p.ThpInfo = string(thpInfo)
|
||||
p.ValidDate = req.ValidDate
|
||||
p.MerUserID = strconv.Itoa(user.ID)
|
||||
p.IdType = "0"
|
||||
p.AcctType = acctType
|
||||
p.ReqIp = "127.0.0.1"
|
||||
p.Version = "11"
|
||||
|
||||
r, err := tlpay.TLPay.AgreeConfirm(p)
|
||||
fmt.Println(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.RetCode != "SUCCESS" {
|
||||
return nil, errors.NewBusinessError(r.RetMsg)
|
||||
}
|
||||
if r.TrxStatus != "0000" {
|
||||
return nil, errors.NewBusinessError(r.ErrMsg)
|
||||
}
|
||||
data := result.Data{"agreeId": r.AgreeID, "bankCode": r.BankCode, "bankName": r.BankName}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (s *userService) GetBankCardByUserID(userID int) (*model.UserBankCard, error) {
|
||||
c := model.UserBankCard{}
|
||||
err := global.DB.Where("user_id", userID).Where("status", 1).First(&c).Error
|
||||
fmt.Println(err)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
func (s *userService) BankCardUnbind(user *model.User) error {
|
||||
c := model.UserBankCard{}
|
||||
err := global.DB.Where("user_id", user.ID).Where("status", 1).First(&c).Error
|
||||
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return errors.NewBusinessError("银行卡不存在")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p := param.UnbindParam{}
|
||||
p.AgreeID = c.AgreeID
|
||||
p.ReqIp = "127.0.0.1"
|
||||
p.Version = "11"
|
||||
r, err := tlpay.TLPay.Unbind(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if r.RetCode != "SUCCESS" {
|
||||
return errors.NewBusinessError(r.RetMsg)
|
||||
}
|
||||
|
||||
c.Status = 3
|
||||
err = global.DB.Save(&c).Error
|
||||
if err != nil {
|
||||
return errors.NewBusinessError("更新失败")
|
||||
}
|
||||
return nil
|
||||
func (userService) GetInfo(id int) *model.User {
|
||||
return &model.User{}
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
package system
|
@ -0,0 +1 @@
|
||||
package alipay
|
@ -1,111 +0,0 @@
|
||||
package alipay
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gold-shop/errors"
|
||||
"gold-shop/global"
|
||||
"gold-shop/utils"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var AlipayApi alipayApi = alipayApi{}
|
||||
|
||||
type alipayApi struct {
|
||||
}
|
||||
|
||||
func (api alipayApi) GetAuthToken(code string) (*AuthTokenResult, error) {
|
||||
|
||||
commonParam := api.buildCommonParam("alipay.system.oauth.token")
|
||||
param := AuthTokenParam{}
|
||||
param.CommonParam = commonParam
|
||||
param.Code = code
|
||||
param.GrantType = "authorization_code"
|
||||
|
||||
p, err := utils.StructToURLValues(param)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sign, err := api.sign(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.Set("sign", sign)
|
||||
|
||||
body, err := api.post(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := AuthTokenResult{}
|
||||
err = json.Unmarshal(body, &result)
|
||||
fmt.Println(result)
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("数据解析错误")
|
||||
}
|
||||
if result.Code != "10000" {
|
||||
return nil, errors.NewBusinessError(result.Msg)
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (api alipayApi) buildCommonParam(method string) CommonParam {
|
||||
param := CommonParam{}
|
||||
param.AppID = global.Config.Payment.AliPay.SubAppId
|
||||
param.Method = method
|
||||
param.Format = "JSON"
|
||||
param.Charset = "utf-8"
|
||||
param.SignType = "RSA2"
|
||||
param.Timestamp = time.Now().Format("2006-01-02 15:04:05")
|
||||
param.Version = "1.0"
|
||||
return param
|
||||
}
|
||||
|
||||
func (api *alipayApi) sign(params url.Values) (string, error) {
|
||||
params.Del("sign")
|
||||
for key, value := range params {
|
||||
if len(value) == 0 || value[0] == "" {
|
||||
params.Del(key)
|
||||
}
|
||||
}
|
||||
signStr, err := url.QueryUnescape(params.Encode())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
fmt.Println("signStr: " + signStr)
|
||||
return utils.RSASign([]byte(signStr), global.Config.Payment.AliPay.SubPriPemFile)
|
||||
}
|
||||
|
||||
func (alipayApi) post(data url.Values) ([]byte, error) {
|
||||
client := &http.Client{}
|
||||
body := strings.NewReader(data.Encode())
|
||||
request, err := http.NewRequest("POST", "https://openapi.alipay.com/gateway.do", body)
|
||||
request.Header.Set("content-type", "application/x-www-form-urlencoded")
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("请求错误")
|
||||
}
|
||||
response, err := client.Do(request)
|
||||
|
||||
defer func(Body io.ReadCloser) {
|
||||
err := Body.Close()
|
||||
if err != nil {
|
||||
|
||||
}
|
||||
}(response.Body)
|
||||
|
||||
bodyBytes, err := io.ReadAll(response.Body)
|
||||
|
||||
fmt.Println(string(bodyBytes))
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("返回内容错误")
|
||||
}
|
||||
|
||||
return bodyBytes, nil
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package alipay
|
||||
|
||||
type AuthTokenParam struct {
|
||||
CommonParam
|
||||
Code string `json:"code"`
|
||||
GrantType string `json:"grant_type"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package alipay
|
||||
|
||||
type AuthTokenResult struct {
|
||||
CommonResult
|
||||
AccessToken string `json:"access_token"`
|
||||
ExpiresIn string `json:"expires_in"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
ReExpiresIn string `json:"re_expires_in"`
|
||||
OpenID string `json:"open_id"`
|
||||
UserID string `json:"user_id"`
|
||||
AuthStart string `json:"auth_start"`
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package alipay
|
||||
|
||||
type CommonParam struct {
|
||||
AppID string `json:"app_id"`
|
||||
Method string `json:"method"`
|
||||
Format string `json:"format"`
|
||||
Charset string `json:"charset"`
|
||||
SignType string `json:"sign_type"`
|
||||
Sign string `json:"sign"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
Version string `json:"version"`
|
||||
AppAuthToken string `json:"app_auth_token"`
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package alipay
|
||||
|
||||
type CommonResult struct {
|
||||
Code string `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
SubCode string `json:"sub_code"`
|
||||
SubMsg string `json:"sub_msg"`
|
||||
Sign string `json:"sign"`
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package payment
|
||||
|
||||
type AliPayParam struct {
|
||||
BuyerId string
|
||||
Amount float64
|
||||
OrderId string
|
||||
NotifyUrl string
|
||||
Remark string
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package payment
|
||||
|
||||
type AliPayResult struct {
|
||||
TradeNo string `json:"trade_no"`
|
||||
OrderID string `json:"orderid"`
|
||||
OrderTime string `json:"order_time"`
|
||||
MchOrderID string `json:"mch_orderid"`
|
||||
Version string `json:"version"`
|
||||
Charset string `json:"charset"`
|
||||
Message string `json:"message"`
|
||||
Status string `json:"status"`
|
||||
SignType string `json:"sign_ype"`
|
||||
Sign string `json:"sign"`
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
package payment
|
||||
|
||||
const Success = "10000"
|
@ -1,164 +0,0 @@
|
||||
package payment
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gold-shop/errors"
|
||||
"gold-shop/global"
|
||||
"gold-shop/utils"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var PayApi payApi = payApi{}
|
||||
|
||||
type payApi struct {
|
||||
}
|
||||
|
||||
func (api *payApi) WxPay(param WxPayParam) (*WxPayResult, error) {
|
||||
payment := global.Config.Payment
|
||||
data := url.Values{}
|
||||
data.Set("service", "comm.js.pay")
|
||||
data.Set("apikey", payment.ApiKey)
|
||||
data.Set("money", fmt.Sprintf("%.2f", param.Amount))
|
||||
data.Set("sub_appid", payment.WxPay.SubAppId)
|
||||
data.Set("sub_openid", param.OpenId)
|
||||
data.Set("nonce_str", utils.GenerateRandomString(32))
|
||||
data.Set("mch_orderid", param.OrderId)
|
||||
data.Set("notify_url", param.NotifyUrl)
|
||||
data.Set("remarks", param.Remark)
|
||||
sign := api.sign(data, payment.SignKey)
|
||||
data.Set("sign", sign)
|
||||
fmt.Println(data.Encode())
|
||||
|
||||
data.Set("notify_url", url.QueryEscape(param.NotifyUrl))
|
||||
|
||||
res, err := api.post(payment.BaseUrl+"/payapi/mini/wxpay", data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := WxPayResult{}
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("结果解析错误")
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (api *payApi) AliPay(param AliPayParam) (*AliPayResult, error) {
|
||||
payment := global.Config.Payment
|
||||
data := url.Values{}
|
||||
data.Set("service", "comm.js.pay")
|
||||
data.Set("apikey", payment.ApiKey)
|
||||
data.Set("money", fmt.Sprintf("%.2f", param.Amount))
|
||||
data.Set("sub_appid", payment.WxPay.SubAppId)
|
||||
data.Set("buyer_id", param.OrderId)
|
||||
data.Set("nonce_str", utils.GenerateRandomString(32))
|
||||
data.Set("mch_orderid", param.OrderId)
|
||||
data.Set("notify_url", param.NotifyUrl)
|
||||
data.Set("remarks", param.Remark)
|
||||
sign := api.sign(data, payment.SignKey)
|
||||
data.Set("sign", sign)
|
||||
fmt.Println(data.Encode())
|
||||
|
||||
data.Set("notify_url", url.QueryEscape(param.NotifyUrl))
|
||||
|
||||
res, err := api.post(payment.BaseUrl+"/payapi/trade/alipay", data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := AliPayResult{}
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("结果解析错误")
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (api *payApi) QueryOrder(param QueryOrderParam) (*QueryOrderResult, error) {
|
||||
payment := global.Config.Payment
|
||||
data := url.Values{}
|
||||
data.Set("service", "pay.comm.query_order")
|
||||
data.Set("apikey", payment.ApiKey)
|
||||
data.Set("orderid", param.OrderID)
|
||||
data.Set("mch_orderid", param.MchOrderID)
|
||||
data.Set("nonce_str", utils.GenerateRandomString(32))
|
||||
data.Set("order_time", strconv.Itoa(int(param.OrderTime)))
|
||||
data.Set("dis_name", param.DisName)
|
||||
sign := api.sign(data, payment.SignKey)
|
||||
data.Set("sign", sign)
|
||||
fmt.Println(data.Encode())
|
||||
res, err := api.post(payment.BaseUrl+"/payapi/pay/query_order", data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := QueryOrderResult{}
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("结果解析错误")
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (api *payApi) TransferPay(param TransferPayParam) (*TransferPayResult, error) {
|
||||
payment := global.Config.Payment
|
||||
data := url.Values{}
|
||||
data.Set("service", "pay.heli.large_query")
|
||||
data.Set("apikey", payment.ApiKey)
|
||||
data.Set("order_money", fmt.Sprintf("%.2f", param.Amount))
|
||||
data.Set("nonce_str", utils.GenerateRandomString(32))
|
||||
data.Set("out_orderid", param.OrderId)
|
||||
//data.Set("notify_url", param.NotifyUrl)
|
||||
//data.Set("remark", param.Remark)
|
||||
sign := api.sign(data, payment.SignKey)
|
||||
data.Set("sign", sign)
|
||||
fmt.Println(data.Encode())
|
||||
fmt.Println("url: " + payment.BaseUrl + "/payapi/pay/large_create")
|
||||
res, err := api.post(payment.BaseUrl+"/payapi/pay/large_create", data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := TransferPayResult{}
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("结果解析错误")
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (payApi) sign(params url.Values, signKey string) string {
|
||||
fmt.Println(params.Encode() + "&signkey=" + signKey)
|
||||
return utils.Md5(params.Encode() + "&signkey=" + signKey)
|
||||
}
|
||||
|
||||
func (payApi) post(url string, data url.Values) ([]byte, error) {
|
||||
client := &http.Client{}
|
||||
body := strings.NewReader(data.Encode())
|
||||
request, err := http.NewRequest("POST", url, body)
|
||||
request.Header.Set("content-type", "application/x-www-form-urlencoded")
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("请求错误")
|
||||
}
|
||||
response, err := client.Do(request)
|
||||
|
||||
defer func(Body io.ReadCloser) {
|
||||
err := Body.Close()
|
||||
if err != nil {
|
||||
|
||||
}
|
||||
}(response.Body)
|
||||
|
||||
bodyBytes, err := io.ReadAll(response.Body)
|
||||
|
||||
fmt.Println(string(bodyBytes))
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("返回内容错误")
|
||||
}
|
||||
|
||||
return bodyBytes, nil
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package payment
|
||||
|
||||
type QueryOrderParam struct {
|
||||
OrderID string
|
||||
DisName string
|
||||
MchOrderID string
|
||||
OrderTime int64
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package payment
|
||||
|
||||
type QueryOrderResult struct {
|
||||
OrderID string `form:"orderid"`
|
||||
TradeNo string `form:"trade_no"`
|
||||
DisName string `form:"dis_name"`
|
||||
PayStatus int `form:"paystatus"`
|
||||
PayMoney float64 `form:"paymoney"`
|
||||
PriPayMoney float64 `form:"pri_paymoney"`
|
||||
OrderTime int64 `form:"order_time"`
|
||||
PayTime int64 `form:"paytime"`
|
||||
MchOrderID string `form:"mch_orderid"`
|
||||
NotifyUrl string `form:"notify_url"`
|
||||
BuyerAccount string `form:"buyer_account"`
|
||||
Attach string `form:"attach"`
|
||||
ReceiptAmount float64 `form:"receipt_amount"`
|
||||
BuyerPayAmount float64 `form:"buyer_pay_amount"`
|
||||
CouponFee float64 `form:"coupon_fee"`
|
||||
Version string `form:"version"`
|
||||
Charset string `form:"charset"`
|
||||
Message string `form:"message"`
|
||||
Status string `form:"status"`
|
||||
Sign string `form:"sign"`
|
||||
SignType string `form:"sign_type"`
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package payment
|
||||
|
||||
type TransferPayParam struct {
|
||||
OpenId string
|
||||
Amount float64
|
||||
OrderId string
|
||||
NotifyUrl string
|
||||
Remark string
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package payment
|
||||
|
||||
type TransferPayResult struct {
|
||||
Service string `json:"service"`
|
||||
OrderID string `json:"orderid"`
|
||||
OutOrderID string `json:"out_orderid"`
|
||||
OrderMoney string `json:"order_money"`
|
||||
PayeeAccountName string `json:"payee_account_name"`
|
||||
PayeeCardNo string `json:"payee_card_no"`
|
||||
PayeeBankName string `json:"payee_bank_name"`
|
||||
Version string `json:"version"`
|
||||
Message string `json:"message"`
|
||||
Status string `json:"status"`
|
||||
SignType string `json:"sign_ype"`
|
||||
Sign string `json:"sign"`
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package payment
|
||||
|
||||
type WxPayParam struct {
|
||||
OpenId string
|
||||
Amount float64
|
||||
OrderId string
|
||||
NotifyUrl string
|
||||
Remark string
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package payment
|
||||
|
||||
type WxPayResult struct {
|
||||
AppId string `json:"appId"`
|
||||
Timestamp string `json:"timeStamp"`
|
||||
NonceStr string `json:"nonceStr"`
|
||||
Package string `json:"package"`
|
||||
PaySign string `json:"paySign"`
|
||||
PaySignType string `json:"signType"`
|
||||
Service string `json:"service"`
|
||||
OrderID string `json:"orderid"`
|
||||
OrderTime string `json:"order_time"`
|
||||
MchOrderID string `json:"mch_orderid"`
|
||||
QrCode string `json:"qr_code"`
|
||||
TradeType string `json:"trade_type"`
|
||||
PrepayId string `json:"prepay_id"`
|
||||
Version string `json:"version"`
|
||||
Charset string `json:"charset"`
|
||||
Message string `json:"message"`
|
||||
Status string `json:"status"`
|
||||
SignType string `json:"sign_ype"`
|
||||
Sign string `json:"sign"`
|
||||
}
|
@ -1,276 +0,0 @@
|
||||
package tlpay
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gold-shop/errors"
|
||||
"gold-shop/global"
|
||||
"gold-shop/utils"
|
||||
"gold-shop/utils/tlpay/param"
|
||||
"gold-shop/utils/tlpay/result"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var TLPay tlPay = tlPay{}
|
||||
|
||||
type tlPay struct {
|
||||
}
|
||||
|
||||
func (api *tlPay) AgreeApply(p param.AgreeApplyParam) (*result.AgreeApplyResult, error) {
|
||||
payConfig := global.Config.TlPay
|
||||
data, err := utils.StructToURLValues(p)
|
||||
data = api.SetCommonParams(data, true)
|
||||
sign, err := api.sign(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println(sign)
|
||||
data.Set("sign", sign)
|
||||
res, err := api.post(payConfig.BaseUrl+"/apiweb/qpay/agreeapply", data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r := result.AgreeApplyResult{}
|
||||
err = json.Unmarshal(res, &r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func (api *tlPay) AgreeConfirm(p param.AgreeConfirmParam) (*result.AgreeConfirmResult, error) {
|
||||
payConfig := global.Config.TlPay
|
||||
data, err := utils.StructToURLValues(p)
|
||||
data = api.SetCommonParams(data, true)
|
||||
sign, err := api.sign(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println(sign)
|
||||
data.Set("sign", sign)
|
||||
res, err := api.post(payConfig.BaseUrl+"/apiweb/qpay/agreeconfirm", data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r := result.AgreeConfirmResult{}
|
||||
err = json.Unmarshal(res, &r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func (api *tlPay) Unbind(p param.UnbindParam) (*result.CommonResult, error) {
|
||||
payConfig := global.Config.TlPay
|
||||
data, err := utils.StructToURLValues(p)
|
||||
data = api.SetCommonParams(data, true)
|
||||
sign, err := api.sign(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println(sign)
|
||||
data.Set("sign", sign)
|
||||
res, err := api.post(payConfig.BaseUrl+"/apiweb/qpay/unbind", data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r := result.CommonResult{}
|
||||
err = json.Unmarshal(res, &r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func (api *tlPay) PayApplyAgree(p param.PayApplyAgreeParam) (*result.PayApplyAgreeResult, error) {
|
||||
payConfig := global.Config.TlPay
|
||||
data, err := utils.StructToURLValues(p)
|
||||
data = api.SetCommonParams(data, true)
|
||||
sign, err := api.sign(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println(sign)
|
||||
data.Set("sign", sign)
|
||||
res, err := api.post(payConfig.BaseUrl+"/apiweb/qpay/payapplyagree", data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r := result.PayApplyAgreeResult{}
|
||||
err = json.Unmarshal(res, &r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func (api *tlPay) PayAgreeConfirm(p param.PayAgreeConfirmParam) (*result.PayAgreeConfirmResult, error) {
|
||||
payConfig := global.Config.TlPay
|
||||
data, err := utils.StructToURLValues(p)
|
||||
data = api.SetCommonParams(data, true)
|
||||
sign, err := api.sign(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println(sign)
|
||||
data.Set("sign", sign)
|
||||
res, err := api.post(payConfig.BaseUrl+"/apiweb/qpay/payagreeconfirm", data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r := result.PayAgreeConfirmResult{}
|
||||
err = json.Unmarshal(res, &r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func (api *tlPay) PaySmsAgree(p param.PaySmsAgreeParam) (*result.PaySmsAgreeResult, error) {
|
||||
payConfig := global.Config.TlPay
|
||||
data, err := utils.StructToURLValues(p)
|
||||
data = api.SetCommonParams(data, true)
|
||||
sign, err := api.sign(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println(sign)
|
||||
data.Set("sign", sign)
|
||||
res, err := api.post(payConfig.BaseUrl+"/apiweb/qpay/paysmsagree", data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r := result.PaySmsAgreeResult{}
|
||||
err = json.Unmarshal(res, &r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func (api *tlPay) SetCommonParams(data url.Values, isNeedReqTime bool) url.Values {
|
||||
payConfig := global.Config.TlPay
|
||||
data.Set("cusid", payConfig.CusID)
|
||||
data.Set("appid", payConfig.AppId)
|
||||
data.Set("randomstr", utils.GenerateRandomString(32))
|
||||
if isNeedReqTime {
|
||||
data.Set("reqtime", time.Now().Format("20060102150405"))
|
||||
}
|
||||
data.Set("signtype", "RSA")
|
||||
return data
|
||||
}
|
||||
|
||||
func (api *tlPay) sign(params url.Values) (string, error) {
|
||||
payConfig := global.Config.TlPay
|
||||
params.Del("sign")
|
||||
for key, value := range params {
|
||||
if len(value) == 0 || value[0] == "" {
|
||||
params.Del(key)
|
||||
}
|
||||
}
|
||||
signStr, err := url.QueryUnescape(params.Encode())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
fmt.Println("signStr: " + signStr)
|
||||
return utils.RSASign([]byte(signStr), payConfig.PriPemFile)
|
||||
}
|
||||
|
||||
func (api *tlPay) Verify(params url.Values) error {
|
||||
payConfig := global.Config.TlPay
|
||||
sign := params.Get("sign")
|
||||
params.Del("sign")
|
||||
for key, value := range params {
|
||||
if len(value) == 0 || value[0] == "" {
|
||||
params.Del(key)
|
||||
}
|
||||
}
|
||||
//signStr, err := url.QueryUnescape(params.Encode())
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
signStr := params.Encode()
|
||||
|
||||
fmt.Println("sign: ", sign)
|
||||
fmt.Println("signStr: ", signStr)
|
||||
return utils.RSAVerify([]byte(signStr), sign, payConfig.PriPemFile)
|
||||
}
|
||||
|
||||
func (api *tlPay) post(url string, data url.Values) ([]byte, error) {
|
||||
client := &http.Client{}
|
||||
body := strings.NewReader(data.Encode())
|
||||
|
||||
fmt.Println("url: " + url)
|
||||
fmt.Println("data: " + data.Encode())
|
||||
request, err := http.NewRequest("POST", url, body)
|
||||
request.Header.Set("content-type", "application/x-www-form-urlencoded")
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("请求错误")
|
||||
}
|
||||
response, err := client.Do(request)
|
||||
|
||||
defer func(Body io.ReadCloser) {
|
||||
err := Body.Close()
|
||||
if err != nil {
|
||||
|
||||
}
|
||||
}(response.Body)
|
||||
|
||||
bodyBytes, err := io.ReadAll(response.Body)
|
||||
|
||||
fmt.Println("res: ", string(bodyBytes))
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("返回内容错误")
|
||||
}
|
||||
|
||||
return bodyBytes, nil
|
||||
}
|
||||
|
||||
func (api *tlPay) GatewayPay(p param.GatewayPayParam) string {
|
||||
data, _ := utils.StructToURLValues(p)
|
||||
data = api.SetCommonParams(data, false)
|
||||
sign, _ := api.sign(data)
|
||||
data.Set("sign", sign)
|
||||
return api.BuildForm(data)
|
||||
}
|
||||
|
||||
func (api *tlPay) BuildForm(data url.Values) string {
|
||||
htmlBegin := `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>充值</title>
|
||||
<meta charset="utf-8">
|
||||
<script>
|
||||
window.onload = function() {
|
||||
document.getElementById("auto-submit-form").submit();
|
||||
};
|
||||
</script>
|
||||
</head>
|
||||
<body>`
|
||||
|
||||
htmlEnd :=
|
||||
`</body>
|
||||
</html>
|
||||
`
|
||||
return htmlBegin + api.buildFormHtml(data) + htmlEnd
|
||||
}
|
||||
|
||||
func (api *tlPay) buildFormHtml(data url.Values) string {
|
||||
payConfig := global.Config.TlPay
|
||||
formUrl := payConfig.BaseUrl + "/apiweb/gateway/pay"
|
||||
formHtml := "<form id=\"auto-submit-form\" action=\"" + formUrl + "\" method=\"POST\">"
|
||||
for key, value := range data {
|
||||
formHtml += "<input type=\"hidden\" name=\"" + key + "\" value=\"" + value[0] + "\">"
|
||||
}
|
||||
|
||||
//formHtml += "<button type=\"submit\">提交</button>"
|
||||
formHtml += "</form>"
|
||||
return formHtml
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package notify
|
||||
|
||||
type GatewayPayRet struct {
|
||||
CusID string `json:"cusid" form:"cusid"`
|
||||
AppID string `json:"appid" form:"appid"`
|
||||
TrxCode string `json:"trxcode" form:"trxcode"`
|
||||
TrxID string `json:"trxid" form:"trxid"`
|
||||
TrxAmt string `json:"trxamt" form:"trxamt"`
|
||||
TrxDate string `json:"trxdate" form:"trxdate"`
|
||||
PayTime string `json:"paytime" form:"paytime"`
|
||||
TrxStatus string `json:"trxstatus" form:"trxstatus"`
|
||||
TrxReserved string `json:"trxreserved" form:"trxreserved"`
|
||||
CusOrderID string `json:"cusorderid" form:"cusorderid"`
|
||||
SignType string `json:"signtype" form:"signtype"`
|
||||
Sign string `json:"sign" form:"sign"`
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package notify
|
||||
|
||||
type PayAgreeNotify struct {
|
||||
CusID string `json:"cusid" form:"cusid"`
|
||||
AppID string `json:"appid" form:"appid"`
|
||||
OutTrxID string `json:"outTrxid" form:"outtrxid"`
|
||||
TrxCode string `json:"trxcode" form:"trxcode"`
|
||||
TrxID string `json:"trxid" form:"trxid"`
|
||||
InitAmt string `json:"initamt" form:"initamt"`
|
||||
TrxAmt string `json:"trxamt" form:"trxamt"`
|
||||
TrxDate string `json:"trxdate" form:"trxdate"`
|
||||
PayTime string `json:"paytime" form:"paytime"`
|
||||
ChannelTrxID string `json:"chnltrxid" form:"chnltrxid"`
|
||||
TrxStatus string `json:"trxstatus" form:"trxstatus"`
|
||||
|
||||
TermNo string `json:"termno" form:"termno"`
|
||||
TermBatchID string `json:"termbatchid" form:"termbatchid"`
|
||||
TermTraceNo string `json:"termtraceno" form:"termtraceno"`
|
||||
TermAuthNo string `json:"termauthno" form:"termauthno"`
|
||||
TermRefNum string `json:"termrefnum" form:"termrefnum"`
|
||||
|
||||
TrxReserved string `json:"trxreserved" form:"trxreserved"`
|
||||
SrcTrxID string `json:"srctrxid" form:"srctrxid"`
|
||||
CusOrderID string `json:"cusorderid" form:"cusorderid"`
|
||||
Acct string `json:"acct" form:"acct"`
|
||||
Fee string `json:"fee" form:"fee"`
|
||||
CmID string `json:"cmid" form:"cmid"`
|
||||
ChannelID string `json:"chnlid" form:"chnlid"`
|
||||
ChannelData string `json:"chnldata" form:"chnldata"`
|
||||
AcctType string `json:"accttype" form:"accttype"`
|
||||
BankCode string `json:"bankcode" form:"bankcode"`
|
||||
LogOnID string `json:"logonid" form:"logonid"`
|
||||
|
||||
SignType string `json:"signtype" form:"signtype"`
|
||||
Sign string `json:"sign" form:"sign"`
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package param
|
||||
|
||||
type AgreeApplyParam struct {
|
||||
CusID string `json:"cusid" form:"cusid"`
|
||||
AppID string `json:"appid" form:"appid"`
|
||||
ReqTime string `json:"reqtime" form:"reqtime"`
|
||||
ReqIp string `json:"reqip" form:"reqip"`
|
||||
Version string `json:"version" form:"version"`
|
||||
RandomStr string `json:"randomstr" form:"randomstr"`
|
||||
SignType string `json:"signtype" form:"signtype"`
|
||||
Sign string `json:"sign" form:"sign"`
|
||||
|
||||
MerUserID string `json:"meruserid" form:"meruserid"`
|
||||
AcctType string `json:"accttype" form:"accttype"`
|
||||
AcctNo string `json:"acctno" form:"acctno"`
|
||||
IdType string `json:"idtype" form:"idtype"`
|
||||
IdNo string `json:"idno" form:"idno"`
|
||||
AcctName string `json:"acctname" form:"acctname"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
ValidDate string `json:"validdate" form:"validdate"`
|
||||
Cvv2 string `json:"cvv2" form:"cvv2"`
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package param
|
||||
|
||||
type AgreeConfirmParam struct {
|
||||
CusID string `json:"cusid" form:"cusid"`
|
||||
AppID string `json:"appid" form:"appid"`
|
||||
ReqTime string `json:"reqtime" form:"reqtime"`
|
||||
ReqIp string `json:"reqip" form:"reqip"`
|
||||
Version string `json:"version" form:"version"`
|
||||
RandomStr string `json:"randomstr" form:"randomstr"`
|
||||
SignType string `json:"signtype" form:"signtype"`
|
||||
Sign string `json:"sign" form:"sign"`
|
||||
|
||||
MerUserID string `json:"meruserid" form:"meruserid"`
|
||||
AcctType string `json:"accttype" form:"accttype"`
|
||||
AcctNo string `json:"acctno" form:"acctno"`
|
||||
IdType string `json:"idtype" form:"idtype"`
|
||||
IdNo string `json:"idno" form:"idno"`
|
||||
AcctName string `json:"acctname" form:"acctname"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
ValidDate string `json:"validdate" form:"validdate"`
|
||||
Cvv2 string `json:"cvv2" form:"cvv2"`
|
||||
SmsCode string `json:"smscode" form:"smscode"`
|
||||
ThpInfo string `json:"thpinfo" form:"thpinfo"`
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package param
|
||||
|
||||
type GatewayPayParam struct {
|
||||
OrgID string `json:"orgid" form:"orgid"`
|
||||
CusID string `json:"cusid" form:"cusid"`
|
||||
AppID string `json:"appid" form:"appid"`
|
||||
Charset string `json:"charset" form:"charset"`
|
||||
RandomStr string `json:"randomstr" form:"randomstr"`
|
||||
SignType string `json:"signtype" form:"signtype"`
|
||||
Sign string `json:"sign" form:"sign"`
|
||||
|
||||
RetUrl string `json:"returl" form:"returl"`
|
||||
NotifyUrl string `json:"notifyurl" form:"notifyurl"`
|
||||
GoodsID string `json:"goodsid" form:"goodsid"`
|
||||
GoodsInf string `json:"goodsinf" form:"goodsinf"`
|
||||
TrxAmt string `json:"trxamt" form:"trxamt"`
|
||||
OrderID string `json:"orderid" form:"orderid"`
|
||||
GateID string `json:"gateid" form:"gateid"`
|
||||
PayType string `json:"paytype" form:"paytype"`
|
||||
LimitPay string `json:"limitpay" form:"limitpay"`
|
||||
ValidTime string `json:"validtime" form:"validtime"`
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package param
|
||||
|
||||
type PayAgreeConfirmParam struct {
|
||||
CusID string `json:"cusid" form:"cusid"`
|
||||
AppID string `json:"appid" form:"appid"`
|
||||
ReqTime string `json:"reqtime" form:"reqtime"`
|
||||
ReqIp string `json:"reqip" form:"reqip"`
|
||||
Version string `json:"version" form:"version"`
|
||||
RandomStr string `json:"randomstr" form:"randomstr"`
|
||||
SignType string `json:"signtype" form:"signtype"`
|
||||
Sign string `json:"sign" form:"sign"`
|
||||
|
||||
ReqSn string `json:"reqsn" form:"reqsn"`
|
||||
AgreeID string `json:"agreeid" form:"agreeid"`
|
||||
SmsCode string `json:"smscode" form:"smscode"`
|
||||
ThpInfo string `json:"thpinfo" form:"thpinfo"`
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package param
|
||||
|
||||
type PayApplyAgreeParam struct {
|
||||
CusID string `json:"cusid" form:"cusid"`
|
||||
AppID string `json:"appid" form:"appid"`
|
||||
ReqTime string `json:"reqtime" form:"reqtime"`
|
||||
ReqIp string `json:"reqip" form:"reqip"`
|
||||
Version string `json:"version" form:"version"`
|
||||
RandomStr string `json:"randomstr" form:"randomstr"`
|
||||
SignType string `json:"signtype" form:"signtype"`
|
||||
Sign string `json:"sign" form:"sign"`
|
||||
|
||||
ReqSn string `json:"reqsn" form:"reqsn"`
|
||||
AgreeID string `json:"agreeid" form:"agreeid"`
|
||||
Amount string `json:"amount" form:"amount"`
|
||||
Currency string `json:"currency" form:"currency"`
|
||||
Subject string `json:"subject" form:"subject"`
|
||||
TrxReserve string `json:"trxreserve" form:"trxreserve"`
|
||||
NotifyUrl string `json:"notifyurl" form:"notifyurl"`
|
||||
AsInfo string `json:"asinfo" form:"asinfo"`
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package param
|
||||
|
||||
type PaySmsAgreeParam struct {
|
||||
CusID string `json:"cusid" form:"cusid"`
|
||||
AppID string `json:"appid" form:"appid"`
|
||||
ReqTime string `json:"reqtime" form:"reqtime"`
|
||||
ReqIp string `json:"reqip" form:"reqip"`
|
||||
Version string `json:"version" form:"version"`
|
||||
RandomStr string `json:"randomstr" form:"randomstr"`
|
||||
SignType string `json:"signtype" form:"signtype"`
|
||||
Sign string `json:"sign" form:"sign"`
|
||||
|
||||
OrderID string `json:"orderid" form:"orderid"`
|
||||
AgreeID string `json:"agreeid" form:"agreeid"`
|
||||
ThpInfo string `json:"thpinfo" form:"thpinfo"`
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package param
|
||||
|
||||
type UnbindParam struct {
|
||||
CusID string `json:"cusid" form:"cusid"`
|
||||
AppID string `json:"appid" form:"appid"`
|
||||
ReqTime string `json:"reqtime" form:"reqtime"`
|
||||
ReqIp string `json:"reqip" form:"reqip"`
|
||||
Version string `json:"version" form:"version"`
|
||||
RandomStr string `json:"randomstr" form:"randomstr"`
|
||||
SignType string `json:"signtype" form:"signtype"`
|
||||
Sign string `json:"sign" form:"sign"`
|
||||
|
||||
AgreeID string `json:"agreeid" form:"agreeid"`
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package result
|
||||
|
||||
type AgreeApplyResult struct {
|
||||
RetCode string `json:"retcode" form:"retcode"`
|
||||
RetMsg string `json:"retmsg" form:"retmsg"`
|
||||
RandomStr string `json:"randomstr" form:"randomstr"`
|
||||
Sign string `json:"sign" form:"sign"`
|
||||
|
||||
TrxStatus string `json:"trxstatus" form:"trxstatus"`
|
||||
ErrMsg string `json:"errmsg" form:"errmsg"`
|
||||
ThpInfo string `json:"thpinfo" form:"thpinfo"`
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package result
|
||||
|
||||
type AgreeConfirmResult struct {
|
||||
CommonResult
|
||||
|
||||
TrxStatus string `json:"trxstatus" form:"trxstatus"`
|
||||
ErrMsg string `json:"errmsg" form:"errmsg"`
|
||||
AgreeID string `json:"agreeid" form:"agreeid"`
|
||||
BankCode string `json:"bankcode" form:"bankcode"`
|
||||
BankName string `json:"bankname" form:"bankname"`
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package result
|
||||
|
||||
type CommonResult struct {
|
||||
RetCode string `json:"retcode" form:"retcode"`
|
||||
RetMsg string `json:"retmsg" form:"retmsg"`
|
||||
RandomStr string `json:"randomstr" form:"randomstr"`
|
||||
Sign string `json:"sign" form:"sign"`
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package result
|
||||
|
||||
type PayAgreeConfirmResult struct {
|
||||
CommonResult
|
||||
|
||||
TrxStatus string `json:"trxstatus" form:"trxstatus"`
|
||||
ReqSn string `json:"reqsn" form:"reqsn"`
|
||||
ErrMsg string `json:"errmsg" form:"errmsg"`
|
||||
TrxID string `json:"trxid" form:"trxid"`
|
||||
ChannelTrxID string `json:"chnltrxid" form:"chnltrxid"`
|
||||
FinTime string `json:"fintime" form:"fintime"`
|
||||
ThpInfo string `json:"thpinfo" form:"thpinfo"`
|
||||
Fee string `json:"fee" form:"fee"`
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package result
|
||||
|
||||
type PayApplyAgreeResult struct {
|
||||
CommonResult
|
||||
|
||||
TrxStatus string `json:"trxstatus" form:"trxstatus"`
|
||||
ReqSn string `json:"reqsn" form:"reqsn"`
|
||||
ErrMsg string `json:"errmsg" form:"errmsg"`
|
||||
TrxID string `json:"trxid" form:"trxid"`
|
||||
ChannelTrxID string `json:"chnltrxid" form:"chnltrxid"`
|
||||
FinTime string `json:"fintime" form:"fintime"`
|
||||
ThpInfo string `json:"thpinfo" form:"thpinfo"`
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package result
|
||||
|
||||
type PaySmsAgreeResult struct {
|
||||
CommonResult
|
||||
|
||||
ThpInfo string `json:"thpinfo" form:"thpinfo"`
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package weixin
|
||||
|
||||
type AccessTokenResult struct {
|
||||
ErrorCode int `json:"errcode"`
|
||||
ErrorMessage string `json:"errmsg"`
|
||||
AccessToken string `json:"access_token"`
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
Openid string `json:"openid"`
|
||||
Scope string `json:"scope"`
|
||||
IsSnapshotuser int `json:"is_snapshotuser"`
|
||||
Unionid string `json:"unionid"`
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
package weixin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gold-shop/errors"
|
||||
"gold-shop/global"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
var WxApi wxApi = wxApi{}
|
||||
|
||||
type wxApi struct {
|
||||
}
|
||||
|
||||
func (api wxApi) GetAccessToken(code string) (*AccessTokenResult, error) {
|
||||
params := url.Values{}
|
||||
params.Set("appid", global.Config.Payment.WxPay.SubAppId)
|
||||
params.Set("secret", global.Config.Payment.WxPay.SubAppSecret)
|
||||
params.Set("code", code)
|
||||
params.Set("grant_type", "authorization_code")
|
||||
urlStr := params.Encode()
|
||||
tokenUrl := "https://api.weixin.qq.com/sns/oauth2/access_token?" + urlStr
|
||||
body, err := api.get(tokenUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := AccessTokenResult{}
|
||||
err = json.Unmarshal(body, &result)
|
||||
fmt.Println(result)
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("数据解析错误")
|
||||
}
|
||||
if result.ErrorCode != 0 && result.ErrorCode != 200 {
|
||||
return nil, errors.NewBusinessError(result.ErrorMessage)
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (api wxApi) GetAuthUrl(redirectUrl string) string {
|
||||
fmt.Println(global.Config)
|
||||
params := url.Values{}
|
||||
params.Set("appid", global.Config.Payment.WxPay.SubAppId)
|
||||
params.Set("redirect_uri", redirectUrl)
|
||||
params.Set("response_type", "code")
|
||||
params.Set("scope", "snsapi_base")
|
||||
params.Set("state", "pay")
|
||||
urlStr := params.Encode()
|
||||
return "https://open.weixin.qq.com/connect/oauth2/authorize?" + urlStr + "#wechat_redirect"
|
||||
}
|
||||
|
||||
func (api wxApi) get(url string) ([]byte, error) {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer func(Body io.ReadCloser) {
|
||||
err := Body.Close()
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
}(resp.Body)
|
||||
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
|
||||
fmt.Println(string(bodyBytes))
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.NewBusinessError("返回内容错误")
|
||||
}
|
||||
|
||||
return bodyBytes, nil
|
||||
}
|
Loading…
Reference in New Issue