mirror of
https://github.com/kongyuebin1/dongfeng-pay.git
synced 2025-12-13 12:39:58 +08:00
提交新项目
This commit is contained in:
40
shop/controllers/page_controller.go
Normal file
40
shop/controllers/page_controller.go
Normal file
@@ -0,0 +1,40 @@
|
||||
/***************************************************
|
||||
** @Desc : This file for ...收银台对接快一
|
||||
** @Time : 2018-8-27 13:50
|
||||
** @Author : Joker
|
||||
** @File : home_action
|
||||
** @Last Modified by : Joker
|
||||
** @Last Modified time: 2018-08-29 17:59:48
|
||||
** @Software: GoLand
|
||||
****************************************************/
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/kvpay/goutils"
|
||||
)
|
||||
|
||||
type HomeAction struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
/*加载首页及数据*/
|
||||
func (c *HomeAction) ShowHome() {
|
||||
//取值
|
||||
siteName := beego.AppConfig.String("site.name")
|
||||
orderNo := goutils.NewContext("Joker").GetUUID()
|
||||
productName := "测试应用-支付功能体验(非商品消费)"
|
||||
|
||||
//数据回显
|
||||
c.Data["siteName"] = siteName
|
||||
c.Data["pname"] = productName
|
||||
c.Data["orderNo"] = orderNo
|
||||
c.TplName = "index.html"
|
||||
}
|
||||
|
||||
func (c *HomeAction) ErrorPage() {
|
||||
flash := beego.ReadFromRequest(&c.Controller)
|
||||
error := flash.Data["error"]
|
||||
c.Data["error"] = error
|
||||
c.TplName = "error.html"
|
||||
}
|
||||
78
shop/controllers/pay.go
Normal file
78
shop/controllers/pay.go
Normal file
@@ -0,0 +1,78 @@
|
||||
/***************************************************
|
||||
** @Desc : This file for ...
|
||||
** @Time : 2019/12/18 17:16
|
||||
** @Author : yuebin
|
||||
** @File : pay
|
||||
** @Last Modified by : yuebin
|
||||
** @Last Modified time: 2019/12/18 17:16
|
||||
** @Software: GoLand
|
||||
****************************************************/
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type PayController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (c *PayController) Pay() {
|
||||
orderNo := strings.TrimSpace(c.GetString("orderid"))
|
||||
flash := beego.NewFlash()
|
||||
if orderNo == "" {
|
||||
flash.Error("订单号为空")
|
||||
flash.Store(&c.Controller)
|
||||
c.Redirect("/error.html", 302)
|
||||
return
|
||||
}
|
||||
amount := strings.TrimSpace(c.GetString("amount"))
|
||||
if !c.judgeAmount(amount) {
|
||||
flash.Error("金额有误")
|
||||
flash.Store(&c.Controller)
|
||||
c.Redirect("/error.html", 302)
|
||||
return
|
||||
}
|
||||
isScan := strings.TrimSpace(c.GetString("SCAN"))
|
||||
isH5 := strings.TrimSpace(c.GetString("H5"))
|
||||
isKj := strings.TrimSpace(c.GetString("KJ"))
|
||||
if strings.Contains(isScan, "SCAN") {
|
||||
//扫码
|
||||
scanShop := new(ScanShopController)
|
||||
scanShop.Prepare()
|
||||
scanShop.Params["orderPrice"] = amount
|
||||
scanShop.Params["payWayCode"] = isScan
|
||||
scanShop.Params["orderNo"] = orderNo
|
||||
response := scanShop.Shop(c.Ctx.Request.Host)
|
||||
if response.Code == 200 {
|
||||
str := "/scan.html?" + "orderNo=" + orderNo + "&orderPrice=" + amount + "&qrCode=" + response.Qrcode + "&payWayCode=" + isScan
|
||||
c.Redirect(str, 302)
|
||||
} else {
|
||||
flash.Error("请求失败,生成二维码失败")
|
||||
flash.Store(&c.Controller)
|
||||
c.Redirect("/error.html", 302)
|
||||
}
|
||||
} else if strings.Contains(isH5, "H5") {
|
||||
|
||||
} else if strings.Contains(isKj, "FAST") {
|
||||
|
||||
} else {
|
||||
flash.Error("不存在这样的支付类型")
|
||||
flash.Store(&c.Controller)
|
||||
c.Redirect("/error.html", 302)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (c *PayController) judgeAmount(amount string) bool {
|
||||
_, err := strconv.ParseFloat(amount, 64)
|
||||
if err != nil {
|
||||
logs.Error("输入金额有误")
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
123
shop/controllers/scan_shop.go
Normal file
123
shop/controllers/scan_shop.go
Normal file
@@ -0,0 +1,123 @@
|
||||
/***************************************************
|
||||
** @Desc : 模拟商户扫码支付请求
|
||||
** @Time : 2019/10/26 9:48
|
||||
** @Author : yuebin
|
||||
** @File : scan
|
||||
** @Last Modified by : yuebin
|
||||
** @Last Modified time: 2019/10/26 9:48
|
||||
** @Software: GoLand
|
||||
****************************************************/
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/httplib"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/skip2/go-qrcode"
|
||||
"github.com/widuu/gojson"
|
||||
"juhe/service/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ScanShopController struct {
|
||||
beego.Controller
|
||||
Params map[string]string
|
||||
}
|
||||
|
||||
type DataJSON struct {
|
||||
Code int
|
||||
Msg string
|
||||
}
|
||||
|
||||
type ResponseJSON struct {
|
||||
Code int
|
||||
Msg string
|
||||
OrderNo string
|
||||
Url string
|
||||
Qrcode string
|
||||
}
|
||||
|
||||
const (
|
||||
HOST = "http://localhost:10081"
|
||||
SCAN_HOST = HOST + "/gateway/scan"
|
||||
H5_HOST = HOST + "/gateway/h5"
|
||||
SYT_HOST = HOST + "/gateway/syt"
|
||||
FAST_HOST = HOST + "/gateway/fast"
|
||||
NOTIFY_URL = HOST + "/shop/notify"
|
||||
RETURN_URL = HOST + "/shop/return"
|
||||
PAY_KEY = "kkkkbmrb9gijhrt0th4naoag"
|
||||
PAY_SERCET = "ssssbmrb9gijhrt0th4naob0"
|
||||
)
|
||||
|
||||
func (c *ScanShopController) Prepare() {
|
||||
c.Params = make(map[string]string)
|
||||
//c.Params["orderNo"] = xid.New().String()
|
||||
c.Params["productName"] = "测试"
|
||||
c.Params["orderPeriod"] = "1"
|
||||
c.Params["osType"] = "1"
|
||||
c.Params["notifyUrl"] = NOTIFY_URL
|
||||
c.Params["returnUrl"] = RETURN_URL
|
||||
c.Params["payKey"] = PAY_KEY
|
||||
}
|
||||
|
||||
func (c *ScanShopController) Shop(requestHost string) *ResponseJSON {
|
||||
|
||||
responseJSON := new(ResponseJSON)
|
||||
|
||||
reqUrl := SCAN_HOST
|
||||
|
||||
keys := utils.SortMap(c.Params)
|
||||
sign := utils.GetMD5Sign(c.Params, keys, PAY_SERCET)
|
||||
c.Params["sign"] = sign
|
||||
req := httplib.Post(reqUrl)
|
||||
for k, v := range c.Params {
|
||||
req.Param(k, v)
|
||||
}
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("扫码请求失败")
|
||||
responseJSON.Code = -1
|
||||
responseJSON.Msg = response + " ;" + err.Error()
|
||||
} else {
|
||||
statusCode := gojson.Json(response).Get("statusCode").Tostring()
|
||||
if statusCode != "00" {
|
||||
msg := gojson.Json(response).Get("msg").Tostring()
|
||||
responseJSON.Code = -1
|
||||
responseJSON.Msg = msg
|
||||
} else {
|
||||
responseJSON.Code = 200
|
||||
payUrl := gojson.Json(response).Get("payURL").Tostring()
|
||||
orderNo := gojson.Json(response).Get("orderNo").Tostring()
|
||||
qrCodePathName := "./static/img/" + orderNo + ".png"
|
||||
qrCode := "/static/img/" + orderNo + ".png"
|
||||
GenerateQrcode(payUrl, qrCodePathName)
|
||||
responseJSON.OrderNo = orderNo
|
||||
responseJSON.Url = payUrl
|
||||
responseJSON.Qrcode = "http://" + requestHost + qrCode
|
||||
}
|
||||
}
|
||||
|
||||
return responseJSON
|
||||
}
|
||||
|
||||
func GenerateQrcode(codeUrl, qrcodePathName string) {
|
||||
err := qrcode.WriteFile(codeUrl, qrcode.Medium, 256, qrcodePathName)
|
||||
if err != nil {
|
||||
logs.Error("generate qrCode fail: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ScanShopController) ScanRender() {
|
||||
orderNo := strings.TrimSpace(c.GetString("orderNo"))
|
||||
orderPrice := strings.TrimSpace(c.GetString("orderPrice"))
|
||||
qrCode := strings.TrimSpace(c.GetString("qrCode"))
|
||||
payWayCode := strings.TrimSpace(c.GetString("payWayCode"))
|
||||
if strings.Contains(payWayCode, "UNION") {
|
||||
c.Data["payTypeName"] = "云闪付app"
|
||||
c.Data["openApp"] = "云闪付app [扫一扫]"
|
||||
}
|
||||
c.Data["qrCode"] = qrCode
|
||||
c.Data["orderNo"] = orderNo
|
||||
c.Data["price"] = orderPrice
|
||||
c.TplName = "pay/scan.html"
|
||||
}
|
||||
Reference in New Issue
Block a user