You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
2.9 KiB
Go
122 lines
2.9 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"github.com/fvbock/endless"
|
|
"github.com/gin-gonic/gin"
|
|
"gold-shop/global"
|
|
"gold-shop/initialize"
|
|
"gold-shop/request"
|
|
"gold-shop/route"
|
|
"gold-shop/utils"
|
|
"net/http"
|
|
"net/url"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
initial()
|
|
//testPay()
|
|
runServer()
|
|
}
|
|
|
|
func initial() {
|
|
var configFilePath string
|
|
flag.StringVar(&configFilePath, "config", "./config.yaml", "配置文件")
|
|
flag.Parse()
|
|
global.Config = initialize.InitConfig(configFilePath)
|
|
global.DB = initialize.InitDB(global.Config)
|
|
global.Redis = initialize.InitRedis(global.Config)
|
|
}
|
|
|
|
func runServer() {
|
|
r := gin.Default()
|
|
s := &http.Server{
|
|
Addr: ":8080",
|
|
Handler: r,
|
|
ReadTimeout: 10 * time.Second,
|
|
WriteTimeout: 10 * time.Second,
|
|
MaxHeaderBytes: 1 << 20,
|
|
}
|
|
route.Initial(r)
|
|
err := endless.ListenAndServe(":"+global.Config.Server.Port, s.Handler)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func payOrder1() {
|
|
params := url.Values{}
|
|
params.Set("service", "pay.order")
|
|
params.Set("apikey", "00014005")
|
|
params.Set("money", "0.01")
|
|
params.Set("nonce_str", "slfksldfs22dfsf")
|
|
//params.Set("sign", "")
|
|
params.Set("auth_token", "555555")
|
|
//params.Set("mch_orderid", "")
|
|
//params.Set("mid", "")
|
|
//params.Set("guid", "")
|
|
params.Set("remarks", "tst")
|
|
sign := utils.Sign(params, "punr8ucu")
|
|
params.Set("sign", sign)
|
|
fmt.Println(params.Encode())
|
|
utils.Post("http://api2uat.lfwin.com/payapi/cash/pay_order", params)
|
|
}
|
|
|
|
func payOrderCommon() {
|
|
params := url.Values{}
|
|
params.Set("service", "comm.js.pay")
|
|
params.Set("apikey", "00014005")
|
|
params.Set("money", "0.01")
|
|
params.Set("sub_appid", "wxb1bec7d809e7cf40")
|
|
params.Set("sub_openid", "ohyVV0v4UBc63GL8D8nlEL0UO5vE")
|
|
params.Set("nonce_str", "slfksldfs22dfsf")
|
|
//params.Set("sign", "")
|
|
params.Set("mch_orderid", "444444444")
|
|
//params.Set("mch_orderid", "")
|
|
//params.Set("notify_url", "")
|
|
//params.Set("guid", "")
|
|
params.Set("remarks", "tst")
|
|
sign := utils.Sign(params, "punr8ucu")
|
|
params.Set("sign", sign)
|
|
fmt.Println(params.Encode())
|
|
utils.Post("http://api2.lfwin.com/payapi/mini/wxpay", params)
|
|
}
|
|
|
|
func payOrder2() {
|
|
params := url.Values{}
|
|
params.Set("grant_type", "client_credentials")
|
|
utils.Post1("https://api.paypal.com/v1/oauth2/token", params)
|
|
}
|
|
|
|
func payOrder3() {
|
|
amount := request.Amount{
|
|
CurrencyCode: "USD",
|
|
Value: "0.01",
|
|
}
|
|
purchaseUnit := request.PurchaseUnit{
|
|
Amount: amount,
|
|
Description: "test",
|
|
CustomId: 1,
|
|
}
|
|
r := request.CheckOutOrderRequest{
|
|
Intent: "CAPTURE",
|
|
PurchaseUnits: []request.PurchaseUnit{
|
|
purchaseUnit,
|
|
},
|
|
ApplicationContext: request.ApplicationContext{
|
|
CancelUrl: "https://www.baidu.com",
|
|
ReturnUrl: "https://www.baidu.com",
|
|
},
|
|
}
|
|
body, err := json.Marshal(r)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
token := "A21AAPb6qISsbMc4lPtdW4imLL13_m0zH1n8CQ_zL-PQgwvaj1g6tM86GqBBAy1NL55KKDTbbuyMDplzDsk8-rCWzNKPxB2-w"
|
|
fmt.Println(string(body))
|
|
utils.Post2("https://api.paypal.com/v2/checkout/orders", string(body), token)
|
|
}
|