|
@@ -1,7 +1,10 @@
|
|
package pay
|
|
package pay
|
|
|
|
|
|
import (
|
|
import (
|
|
- "encoding/xml"
|
|
|
|
|
|
+ "bytes"
|
|
|
|
+ "encoding/base64"
|
|
|
|
+ "encoding/hex"
|
|
|
|
+ "encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
"jfw/config"
|
|
"jfw/config"
|
|
"jfw/tools"
|
|
"jfw/tools"
|
|
@@ -25,14 +28,13 @@ type WxPayAction struct {
|
|
payIndex xweb.Mapper `xweb:"/weixin/pay/index"` //微信支付页面
|
|
payIndex xweb.Mapper `xweb:"/weixin/pay/index"` //微信支付页面
|
|
wxPay xweb.Mapper `xweb:"/weixin/pay/pay"` //微信支付
|
|
wxPay xweb.Mapper `xweb:"/weixin/pay/pay"` //微信支付
|
|
//pc端扫码支付
|
|
//pc端扫码支付
|
|
- sacnPay_GetQrCode xweb.Mapper `xweb:"/weixin/sacnPay/getQrCode"` //生成支付二维码
|
|
|
|
|
|
+ sacnPay_WaitPay xweb.Mapper `xweb:"/weixin/sacnPay/waitPay"` //生成支付二维码
|
|
sacnPay_CreateOrder xweb.Mapper `xweb:"/weixin/sacnPay/createOrder"` //创建订单
|
|
sacnPay_CreateOrder xweb.Mapper `xweb:"/weixin/sacnPay/createOrder"` //创建订单
|
|
//统一回调函数
|
|
//统一回调函数
|
|
payCallback xweb.Mapper `xweb:"/weixin/pay/callback"` //微信支付回调
|
|
payCallback xweb.Mapper `xweb:"/weixin/pay/callback"` //微信支付回调
|
|
}
|
|
}
|
|
|
|
|
|
type WeixinStruct struct {
|
|
type WeixinStruct struct {
|
|
- payCallBackChan chan bool
|
|
|
|
appid string
|
|
appid string
|
|
mchid string
|
|
mchid string
|
|
key string
|
|
key string
|
|
@@ -44,13 +46,28 @@ type WeixinStruct struct {
|
|
sjdc_detailmsg string
|
|
sjdc_detailmsg string
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (w *WeixinStruct) getTradeno(tp string) string {
|
|
|
|
+ return fmt.Sprintf("%s_%d%s%s", tp, time.Now().UnixNano(), util.GetRandom(5), util.GetLetterRandom(6))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (w *WeixinStruct) getOrdercode(id string) string {
|
|
|
|
+ hexid := hex.EncodeToString([]byte(id))
|
|
|
|
+ p := len(hexid) - 6
|
|
|
|
+ str := ""
|
|
|
|
+ if p < 0 {
|
|
|
|
+ str = hexid[:] + util.GetRandom(-p)
|
|
|
|
+ } else {
|
|
|
|
+ str = hexid[len(hexid)-6:]
|
|
|
|
+ }
|
|
|
|
+ return str + util.GetRandom(6)
|
|
|
|
+}
|
|
|
|
+
|
|
var weixinStruct *WeixinStruct
|
|
var weixinStruct *WeixinStruct
|
|
|
|
|
|
func init() {
|
|
func init() {
|
|
xweb.AddAction(&WxPayAction{})
|
|
xweb.AddAction(&WxPayAction{})
|
|
payConfig := config.WeixinConfig["pay"].(map[string]interface{})
|
|
payConfig := config.WeixinConfig["pay"].(map[string]interface{})
|
|
weixinStruct = &WeixinStruct{
|
|
weixinStruct = &WeixinStruct{
|
|
- payCallBackChan: make(chan bool, 1),
|
|
|
|
appid: util.ObjToString(config.WeixinConfig["appid"]),
|
|
appid: util.ObjToString(config.WeixinConfig["appid"]),
|
|
mchid: util.ObjToString(payConfig["mchid"]),
|
|
mchid: util.ObjToString(payConfig["mchid"]),
|
|
key: util.ObjToString(payConfig["key"]),
|
|
key: util.ObjToString(payConfig["key"]),
|
|
@@ -126,9 +143,11 @@ func (p *WxPayAction) WxPay() error {
|
|
}
|
|
}
|
|
totalfee := util.IntAll(tf * 100)
|
|
totalfee := util.IntAll(tf * 100)
|
|
title := p.GetString("title")
|
|
title := p.GetString("title")
|
|
- tradeno := "jy-" + fmt.Sprint(time.Now().Unix()) + util.Uuid(12)
|
|
|
|
|
|
+ tradeno := weixinStruct.getTradeno("a")
|
|
//获取预订单号
|
|
//获取预订单号
|
|
ret, err := tools.GetPrepayId(map[string]string{
|
|
ret, err := tools.GetPrepayId(map[string]string{
|
|
|
|
+ "appid": weixinStruct.appid,
|
|
|
|
+ "tradeType": "JSAPI",
|
|
"attachmsg": weixinStruct.dashang_attachmsg,
|
|
"attachmsg": weixinStruct.dashang_attachmsg,
|
|
"bodymsg": weixinStruct.dashang_bodymsg,
|
|
"bodymsg": weixinStruct.dashang_bodymsg,
|
|
"detailmsg": fmt.Sprintf(weixinStruct.dashang_detailmsg, title, fmt.Sprint(float64(totalfee)/100)),
|
|
"detailmsg": fmt.Sprintf(weixinStruct.dashang_detailmsg, title, fmt.Sprint(float64(totalfee)/100)),
|
|
@@ -146,10 +165,10 @@ func (p *WxPayAction) WxPay() error {
|
|
})
|
|
})
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
- prepayId, _ := (*ret)["prepayid"].(string)
|
|
|
|
|
|
+ prepayId := (*ret)["prepayid"]
|
|
if prepayId == "" {
|
|
if prepayId == "" {
|
|
p.ServeJson(map[string]interface{}{
|
|
p.ServeJson(map[string]interface{}{
|
|
- "status": (*ret)["status"],
|
|
|
|
|
|
+ "status": util.IntAll((*ret)["status"]),
|
|
})
|
|
})
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
@@ -200,69 +219,60 @@ func (p *WxPayAction) WxPay() error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
func (p *WxPayAction) PayCallback() {
|
|
func (p *WxPayAction) PayCallback() {
|
|
- weixinStruct.payCallBackChan <- true
|
|
|
|
- defer func() {
|
|
|
|
- <-weixinStruct.payCallBackChan
|
|
|
|
- }()
|
|
|
|
by := p.Body()
|
|
by := p.Body()
|
|
fmt.Println("回调通知参数", string(by))
|
|
fmt.Println("回调通知参数", string(by))
|
|
- ret := struct {
|
|
|
|
- Appid string `xml:"appid"`
|
|
|
|
- Attach string `xml:"attach"`
|
|
|
|
- BankType string `xml:"bank_type"`
|
|
|
|
- CashFee int `xml:"cash_fee"`
|
|
|
|
- FeeType string `xml:"fee_type"`
|
|
|
|
- IsSubscribe string `xml:"is_subscribe"`
|
|
|
|
- MchId string `xml:"mch_id"`
|
|
|
|
- NonceStr string `xml:"nonce_str"`
|
|
|
|
- OpenId string `xml:"openid"`
|
|
|
|
- OutTradeNo string `xml:"out_trade_no"`
|
|
|
|
- ResultCode string `xml:"result_code"`
|
|
|
|
- ReturnCode string `xml:"return_code"`
|
|
|
|
- Sign string `xml:"sign"`
|
|
|
|
- TimeEnd string `xml:"time_end"`
|
|
|
|
- TotalFee string `xml:"total_fee"`
|
|
|
|
- TradeType string `xml:"trade_type"`
|
|
|
|
- TransactionId string `xml:"transaction_id"` //微信支付订单号
|
|
|
|
- }{}
|
|
|
|
- err := xml.Unmarshal(by, &ret)
|
|
|
|
- if err == nil {
|
|
|
|
- if ret.ReturnCode == "SUCCESS" && ret.Appid == weixinStruct.appid && ret.MchId == weixinStruct.mchid {
|
|
|
|
- sign := util.WxSign("appid=%s&attach=%s&bank_type=%s&cash_fee=%d&fee_type=%s&is_subscribe=%s&mch_id=%s&nonce_str=%s&openid=%s&out_trade_no=%s&result_code=%s&return_code=%s&time_end=%s&total_fee=%s&trade_type=%s&transaction_id=%s&key=%s", ret.Appid, ret.Attach, ret.BankType, ret.CashFee, ret.FeeType, ret.IsSubscribe, ret.MchId, ret.NonceStr, ret.OpenId, ret.OutTradeNo, ret.ResultCode, ret.ReturnCode, ret.TimeEnd, ret.TotalFee, ret.TradeType, ret.TransactionId, weixinStruct.key)
|
|
|
|
- if ret.Sign == sign {
|
|
|
|
- //打赏
|
|
|
|
- if strings.HasPrefix(ret.OutTradeNo, "jy_") {
|
|
|
|
- query := map[string]interface{}{
|
|
|
|
- "s_openid": ret.OpenId,
|
|
|
|
- "s_tradeno": ret.OutTradeNo,
|
|
|
|
- "i_totalfee": ret.CashFee,
|
|
|
|
- "i_status": 0,
|
|
|
|
- }
|
|
|
|
- tools.MQFW.Update("reward", query, map[string]interface{}{
|
|
|
|
- "$set": map[string]interface{}{
|
|
|
|
- "i_status": 1,
|
|
|
|
- "s_timeend": ret.TimeEnd,
|
|
|
|
- "l_updatetime": time.Now().Unix(),
|
|
|
|
- "s_transactionid": ret.TransactionId,
|
|
|
|
- },
|
|
|
|
- }, false, false)
|
|
|
|
- } else if strings.HasPrefix(ret.OutTradeNo, "jysjdc_") { //订阅数据导出
|
|
|
|
- //操作mysql库
|
|
|
|
-
|
|
|
|
|
|
+ ret := util.XmlToMap(string(by))
|
|
|
|
+ log.Println(ret)
|
|
|
|
+ if ret["return_code"] == "SUCCESS" && ret["appid"] == weixinStruct.appid && ret["mch_id"] == weixinStruct.mchid {
|
|
|
|
+ if ret["sign"] == util.CreateWxSign(fmt.Sprintf("&key=%s", weixinStruct.key), ret) {
|
|
|
|
+ if strings.HasPrefix(ret["out_trade_no"], "a_") { //打赏
|
|
|
|
+ query := map[string]interface{}{
|
|
|
|
+ "s_openid": ret["openid"],
|
|
|
|
+ "s_tradeno": ret["out_trade_no"],
|
|
|
|
+ "i_totalfee": util.IntAll(ret["cash_fee"]),
|
|
|
|
+ "i_status": 0,
|
|
|
|
+ }
|
|
|
|
+ tools.MQFW.Update("reward", query, map[string]interface{}{
|
|
|
|
+ "$set": map[string]interface{}{
|
|
|
|
+ "i_status": 1,
|
|
|
|
+ "s_timeend": ret["time_end"],
|
|
|
|
+ "l_updatetime": time.Now().Unix(),
|
|
|
|
+ "s_transactionid": ret["transaction_id"],
|
|
|
|
+ },
|
|
|
|
+ }, false, false)
|
|
|
|
+ } else if strings.HasPrefix(ret["out_trade_no"], "b_") { //订阅数据导出
|
|
|
|
+ now := time.Now()
|
|
|
|
+ payid := tools.Mysql.Insert("weixin_pay", map[string]interface{}{
|
|
|
|
+ "transaction_id": ret["transaction_id"],
|
|
|
|
+ "out_trade_no": ret["out_trade_no"],
|
|
|
|
+ "user_openid": ret["openid"],
|
|
|
|
+ "create_time": util.FormatDate(&now, util.Date_Full_Layout),
|
|
|
|
+ "total_fee": util.IntAll(ret["total_fee"]),
|
|
|
|
+ "cash_fee": util.IntAll(ret["cash_fee"]),
|
|
|
|
+ "time_end": ret["time_end"],
|
|
|
|
+ })
|
|
|
|
+ if payid > 0 {
|
|
|
|
+ tools.Mysql.Update("dataexport_order", map[string]interface{}{
|
|
|
|
+ "order_status": 0,
|
|
|
|
+ "out_trade_no": ret["out_trade_no"],
|
|
|
|
+ }, map[string]interface{}{
|
|
|
|
+ "pay_id": payid,
|
|
|
|
+ "pay_money": util.IntAll(ret["cash_fee"]),
|
|
|
|
+ "pay_time": util.FormatDate(&now, util.Date_Full_Layout),
|
|
|
|
+ "order_status": 1,
|
|
|
|
+ })
|
|
}
|
|
}
|
|
- p.Write(`<xml>
|
|
|
|
|
|
+ }
|
|
|
|
+ p.Write(`<xml>
|
|
<return_code><![CDATA[SUCCESS]]></return_code>
|
|
<return_code><![CDATA[SUCCESS]]></return_code>
|
|
<return_msg><![CDATA[OK]]></return_msg>
|
|
<return_msg><![CDATA[OK]]></return_msg>
|
|
</xml>`)
|
|
</xml>`)
|
|
- return
|
|
|
|
- } else {
|
|
|
|
- log.Println("支付回调签名校验未通过!")
|
|
|
|
- }
|
|
|
|
|
|
+ return
|
|
} else {
|
|
} else {
|
|
- log.Println("支付回调参数校验未通过!")
|
|
|
|
|
|
+ log.Println("支付回调签名校验未通过!", ret["openid"])
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- log.Println(err.Error())
|
|
|
|
|
|
+ log.Println("支付回调参数校验未通过!", ret["openid"])
|
|
}
|
|
}
|
|
p.Write(`<xml>
|
|
p.Write(`<xml>
|
|
<return_code><![CDATA[FAIL]]></return_code>
|
|
<return_code><![CDATA[FAIL]]></return_code>
|
|
@@ -285,28 +295,150 @@ func (c *WxPayAction) Qr(code string) error {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
func (p *WxPayAction) SacnPay_CreateOrder() {
|
|
func (p *WxPayAction) SacnPay_CreateOrder() {
|
|
- money, _ := p.GetInt("money")
|
|
|
|
- content := p.GetString("content")
|
|
|
|
- openId, _ := p.GetSession("s_m_openid").(string)
|
|
|
|
|
|
+ user_mail := p.GetString("user_mail")
|
|
|
|
+ data_spec := p.GetString("data_spec")
|
|
//
|
|
//
|
|
- money = 1
|
|
|
|
- content = "jsdlkfjsdlkfj"
|
|
|
|
- openId = "test"
|
|
|
|
- if content == "" || openId == "" {
|
|
|
|
|
|
+ id := p.GetString("id")
|
|
|
|
+ openId := p.GetString("s_m_openid")
|
|
|
|
+ order_money, _ := p.GetInteger("order_money")
|
|
|
|
+ data_count, _ := p.GetInteger("data_count")
|
|
|
|
+ original_price, _ := p.GetInteger("original_price")
|
|
|
|
+ //
|
|
|
|
+ if id == "" || openId == "" || data_spec == "" || order_money <= 0 || data_count <= 0 || original_price <= 0 {
|
|
|
|
+ log.Println("参数不合法!", id, openId, data_spec, order_money, data_count, original_price)
|
|
|
|
+ p.ServeJson(map[string]interface{}{"status": "n"})
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ filter_keys, filter_publishtime, filter := "", "", ""
|
|
|
|
+ userfilter, ok := tools.MQFW.FindById("export_search", id, nil)
|
|
|
|
+ if ok && userfilter != nil {
|
|
|
|
+ keywords, _ := (*userfilter)["keywords"].([]interface{})
|
|
|
|
+ var buffer bytes.Buffer
|
|
|
|
+ for _, v := range keywords {
|
|
|
|
+ vm, _ := v.(map[string]interface{})
|
|
|
|
+ if buffer.Len() > 0 {
|
|
|
|
+ buffer.WriteString(",")
|
|
|
|
+ }
|
|
|
|
+ buffer.WriteString(util.ObjToString(vm["keyword"]))
|
|
|
|
+ }
|
|
|
|
+ filter_keys = buffer.String()
|
|
|
|
+ if strings.TrimSpace(filter_keys) == "" {
|
|
|
|
+ log.Println("关键词为空", openId, id)
|
|
|
|
+ p.ServeJson(map[string]interface{}{"status": "n"})
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ filter_publishtime = util.ObjToString((*userfilter)["publishtime"])
|
|
|
|
+ filterByte, _ := json.Marshal(userfilter)
|
|
|
|
+ filter = string(filterByte)
|
|
|
|
+ } else {
|
|
|
|
+ log.Println("id is not find in mongodb", openId, id)
|
|
p.ServeJson(map[string]interface{}{"status": "n"})
|
|
p.ServeJson(map[string]interface{}{"status": "n"})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
nickname, _ := p.GetSession("s_nickname").(string)
|
|
nickname, _ := p.GetSession("s_nickname").(string)
|
|
- totalfee := 1
|
|
|
|
- tradeno := "jysjdc-" + fmt.Sprint(time.Now().Unix()) + util.Uuid(12)
|
|
|
|
|
|
+ tradeno, ret := CreateOrder(p.IP(), openId, order_money)
|
|
|
|
+ //存库
|
|
|
|
+ log.Println("ret", ret)
|
|
|
|
+ result := map[string]interface{}{
|
|
|
|
+ "status": "n",
|
|
|
|
+ }
|
|
|
|
+ if ret != nil && (*ret)["status"] == "1" {
|
|
|
|
+ now := time.Now()
|
|
|
|
+ ordercode := weixinStruct.getOrdercode(openId)
|
|
|
|
+ orderid := tools.Mysql.Insert("dataexport_order", map[string]interface{}{
|
|
|
|
+ "order_money": order_money,
|
|
|
|
+ "order_status": 0,
|
|
|
|
+ "user_nickname": nickname,
|
|
|
|
+ "user_openid": openId,
|
|
|
|
+ "filter": filter,
|
|
|
|
+ "prepay_id": (*ret)["prepayid"],
|
|
|
|
+ "code_url": (*ret)["codeurl"],
|
|
|
|
+ "out_trade_no": tradeno,
|
|
|
|
+ "order_code": ordercode,
|
|
|
|
+ "product_type": "历史数据",
|
|
|
|
+ "create_time": util.FormatDate(&now, util.Date_Full_Layout),
|
|
|
|
+ "prepay_time": util.FormatDate(&now, util.Date_Full_Layout),
|
|
|
|
+ "original_price": original_price,
|
|
|
|
+ "data_spec": data_spec,
|
|
|
|
+ "user_mail": user_mail,
|
|
|
|
+ "data_count": data_count,
|
|
|
|
+ "filter_publishtime": filter_publishtime,
|
|
|
|
+ "filter_keys": filter_keys,
|
|
|
|
+ })
|
|
|
|
+ if orderid > 0 {
|
|
|
|
+ result["status"] = "y"
|
|
|
|
+ result["code"] = ordercode
|
|
|
|
+ result["token"] = util.GetMd5String(fmt.Sprintf("%s_%d_%s_%s", fmt.Sprint(orderid), order_money, ordercode, openId))
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ log.Println("生成预支付交易单失败", ret)
|
|
|
|
+ }
|
|
|
|
+ p.ServeJson(result)
|
|
|
|
+}
|
|
|
|
+func (p *WxPayAction) SacnPay_WaitPay() error {
|
|
|
|
+ openid := p.GetString("s_m_openid")
|
|
|
|
+ code := p.GetString("code")
|
|
|
|
+ token := p.GetString("token")
|
|
|
|
+ surplus, money, qrcode := func() (int64, int, string) {
|
|
|
|
+ if openid == "" || code == "" || token == "" {
|
|
|
|
+ return 0, 0, ""
|
|
|
|
+ }
|
|
|
|
+ data := tools.Mysql.FindOne("dataexport_order", map[string]interface{}{"order_code": code, "user_openid": openid}, "id,code_url,prepay_time,order_money", "")
|
|
|
|
+ if data == nil {
|
|
|
|
+ log.Println("订单号不存在!", openid)
|
|
|
|
+ return 0, 0, ""
|
|
|
|
+ }
|
|
|
|
+ orderid := (*data)["id"]
|
|
|
|
+ orderMoney := util.IntAll((*data)["order_money"])
|
|
|
|
+ realToken := util.GetMd5String(fmt.Sprintf("%s_%d_%s_%s", fmt.Sprint(orderid), orderMoney, code, openid))
|
|
|
|
+ if realToken != token {
|
|
|
|
+ log.Println("token错误!", openid, realToken, token)
|
|
|
|
+ return 0, 0, ""
|
|
|
|
+ }
|
|
|
|
+ prepayTime, err := time.ParseInLocation(util.Date_Full_Layout, util.ObjToString((*data)["prepay_time"]), time.Local)
|
|
|
|
+ surplus_second := prepayTime.Unix() + 7200 - time.Now().Unix()
|
|
|
|
+ codeUrl := util.ObjToString((*data)["code_url"])
|
|
|
|
+ if err == nil && surplus_second <= 0 {
|
|
|
|
+ log.Println("二维码已失效,重新生成预订单!", openid)
|
|
|
|
+ //重新生成预订单
|
|
|
|
+ tradeno, ret := CreateOrder(p.IP(), openid, orderMoney)
|
|
|
|
+ if ret != nil {
|
|
|
|
+ now := time.Now()
|
|
|
|
+ tools.Mysql.Update("dataexport_order", map[string]interface{}{
|
|
|
|
+ "id": orderid,
|
|
|
|
+ }, map[string]interface{}{
|
|
|
|
+ "prepay_time": util.FormatDate(&now, util.Date_Full_Layout),
|
|
|
|
+ "prepay_id": (*ret)["prepayid"],
|
|
|
|
+ "code_url": (*ret)["codeurl"],
|
|
|
|
+ "out_trade_no": tradeno,
|
|
|
|
+ })
|
|
|
|
+ codeUrl = (*ret)["codeurl"]
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ r, _ := qr.Encode(codeUrl, qr.M)
|
|
|
|
+ pngdat := r.PNG()
|
|
|
|
+ return surplus_second, orderMoney, base64.StdEncoding.EncodeToString(pngdat)
|
|
|
|
+ }()
|
|
|
|
+ p.T["money"] = money / 100
|
|
|
|
+ p.T["surplus_second"] = surplus
|
|
|
|
+ p.T["qrcode"] = qrcode
|
|
|
|
+ return p.Render("/pc/waitpay.html")
|
|
|
|
+}
|
|
|
|
+func CreateOrder(ip, openid string, totalfee int) (string, *map[string]string) {
|
|
|
|
+ tradeno := weixinStruct.getTradeno("b")
|
|
//获取预订单号
|
|
//获取预订单号
|
|
- ret, err := tools.GetPrepayId(map[string]string{
|
|
|
|
|
|
+ // ret := &map[string]string{
|
|
|
|
+ // "codeurl": "weixin://wxpay/bizpayurl?pr=qB27xT8",
|
|
|
|
+ // "prepayid": "wx06105853258077449e64d6b30019026208",
|
|
|
|
+ // "status": "1",
|
|
|
|
+ // }
|
|
|
|
+ ret, _ := tools.GetPrepayId(map[string]string{
|
|
"attachmsg": weixinStruct.sjdc_attachmsg,
|
|
"attachmsg": weixinStruct.sjdc_attachmsg,
|
|
"bodymsg": weixinStruct.sjdc_bodymsg,
|
|
"bodymsg": weixinStruct.sjdc_bodymsg,
|
|
"detailmsg": weixinStruct.sjdc_detailmsg,
|
|
"detailmsg": weixinStruct.sjdc_detailmsg,
|
|
- "useropenid": openId,
|
|
|
|
|
|
+ "useropenid": openid,
|
|
"tradeno": tradeno,
|
|
"tradeno": tradeno,
|
|
- "userip": p.IP(),
|
|
|
|
|
|
+ "userip": ip,
|
|
"totalfee": fmt.Sprint(totalfee),
|
|
"totalfee": fmt.Sprint(totalfee),
|
|
"mchid": weixinStruct.mchid,
|
|
"mchid": weixinStruct.mchid,
|
|
"key": weixinStruct.key,
|
|
"key": weixinStruct.key,
|
|
@@ -314,41 +446,5 @@ func (p *WxPayAction) SacnPay_CreateOrder() {
|
|
"appid": weixinStruct.appid,
|
|
"appid": weixinStruct.appid,
|
|
"tradeType": "NATIVE",
|
|
"tradeType": "NATIVE",
|
|
})
|
|
})
|
|
- //存库
|
|
|
|
- log.Println(ret)
|
|
|
|
- result := map[string]interface{}{}
|
|
|
|
- if err != nil && ret != nil && util.IntAll((*ret)["status"]) == 1 {
|
|
|
|
- now := time.Now()
|
|
|
|
- tools.Mysql.Insert("jianyu_order", map[string]interface{}{
|
|
|
|
- "order_money": money,
|
|
|
|
- "user_nickname": nickname,
|
|
|
|
- "user_openid": openId,
|
|
|
|
- "content": content,
|
|
|
|
- "prepay_id": (*ret)["prepayid"],
|
|
|
|
- "code_url": (*ret)["codeurl"],
|
|
|
|
- "out_trade_no": tradeno,
|
|
|
|
- "create_time": util.FormatDate(&now, util.Date_Full_Layout),
|
|
|
|
- })
|
|
|
|
- result["status"] = "y"
|
|
|
|
- result["code"] = tradeno
|
|
|
|
- result["token"] = (*ret)["sign"]
|
|
|
|
- } else {
|
|
|
|
- log.Println("生成预支付交易单失败", ret)
|
|
|
|
- result["status"] = "n"
|
|
|
|
- }
|
|
|
|
- p.ServeJson(result)
|
|
|
|
-}
|
|
|
|
-func (p *WxPayAction) SacnPay_GetQrCode() error {
|
|
|
|
- code := p.GetString("code")
|
|
|
|
- //sign := p.GetString("sign")
|
|
|
|
- w := p.ResponseWriter
|
|
|
|
- w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
|
- w.Header().Set("Pragma", "no-cache")
|
|
|
|
- w.Header().Set("Expires", "0")
|
|
|
|
- w.Header().Set("Content-Type", "image/png")
|
|
|
|
- data := fmt.Sprintf("%s/front/pay/redirect?id=%s&source=p", config.Sysconfig["webdomain"].(string), code)
|
|
|
|
- r, _ := qr.Encode(data, qr.M)
|
|
|
|
- pngdat := r.PNG()
|
|
|
|
- _, err := w.Write(pngdat)
|
|
|
|
- return err
|
|
|
|
|
|
+ return tradeno, ret
|
|
}
|
|
}
|