75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package web
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/gin/engine"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/lego/utils/crypto/md5"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
"net/http"
|
|
)
|
|
|
|
type PayDeliveryResults struct {
|
|
Code int32 `json:"s"`
|
|
State int32 `json:"state"`
|
|
}
|
|
|
|
// 充值发货
|
|
func (this *Api_Comp) PayDelivery(c *engine.Context) {
|
|
uid := c.Query("uid")
|
|
pid := c.Query("productid")
|
|
oid := c.Query("orderid")
|
|
price := utils.ToInt32(c.Query("price"))
|
|
sign := c.Query("sign")
|
|
// req := make([]interface{}, 0)
|
|
// err := c.BindJSON(&req)
|
|
var (
|
|
payreq *pb.HttpPayDeliveryReq = &pb.HttpPayDeliveryReq{
|
|
Uid: uid,
|
|
Productid: pid,
|
|
Orderid: oid,
|
|
Price: price,
|
|
Amount: 1,
|
|
}
|
|
payresp *pb.HttpPayDeliveryResp = &pb.HttpPayDeliveryResp{
|
|
Code: 0,
|
|
Msg: "成功",
|
|
Data: "",
|
|
}
|
|
)
|
|
this.module.Debugf("PayDelivery:%+v", payreq)
|
|
defer func() {
|
|
if payresp.Code != 0 {
|
|
if payresp.Code != pb.ErrorCode_PayOrderCompleted {
|
|
c.JSON(http.StatusOK, &PayDeliveryResults{Code: 2})
|
|
} else {
|
|
c.JSON(http.StatusOK, &PayDeliveryResults{Code: 3, State: 1})
|
|
}
|
|
|
|
} else {
|
|
c.JSON(http.StatusOK, &PayDeliveryResults{Code: 1})
|
|
}
|
|
|
|
}()
|
|
sginStr := fmt.Sprintf("%s%s%s%d%s", payreq.Uid, payreq.Productid, payreq.Orderid, payreq.Price, this.options.Key)
|
|
_sign := md5.MD5(sginStr)
|
|
if _sign != sign {
|
|
payresp.Code = pb.ErrorCode_SignError
|
|
payresp.Msg = pb.GetErrorCodeMsg(pb.ErrorCode_SignError)
|
|
log.Errorf("签名错误 sign:%s _sign:%s", sign, _sign)
|
|
return
|
|
}
|
|
if err := this.module.service.RpcCall(
|
|
context.TODO(),
|
|
comm.Service_Worker,
|
|
string(comm.Rpc_ModulePayDelivery),
|
|
payreq,
|
|
payresp); err != nil {
|
|
this.module.Errorln(err)
|
|
payresp.Code = pb.ErrorCode_RpcFuncExecutionError
|
|
}
|
|
}
|