MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / EpayNotify

Function EpayNotify

controller/topup.go:178–239  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

176}
177
178func EpayNotify(c *gin.Context) {
179 params := lo.Reduce(lo.Keys(c.Request.URL.Query()), func(r map[string]string, t string, i int) map[string]string {
180 r[t] = c.Request.URL.Query().Get(t)
181 return r
182 }, map[string]string{})
183 client := GetEpayClient()
184 if client == nil {
185 log.Println("易支付回调失败 未找到配置信息")
186 _, err := c.Writer.Write([]byte("fail"))
187 if err != nil {
188 log.Println("易支付回调写入失败")
189 return
190 }
191 }
192 verifyInfo, err := client.Verify(params)
193 if err == nil && verifyInfo.VerifyStatus {
194 _, err := c.Writer.Write([]byte("success"))
195 if err != nil {
196 log.Println("易支付回调写入失败")
197 }
198 } else {
199 _, err := c.Writer.Write([]byte("fail"))
200 if err != nil {
201 log.Println("易支付回调写入失败")
202 }
203 log.Println("易支付回调签名验证失败")
204 return
205 }
206
207 if verifyInfo.TradeStatus == epay.StatusTradeSuccess {
208 log.Println(verifyInfo)
209 LockOrder(verifyInfo.ServiceTradeNo)
210 defer UnlockOrder(verifyInfo.ServiceTradeNo)
211 topUp := model.GetTopUpByTradeNo(verifyInfo.ServiceTradeNo)
212 if topUp == nil {
213 log.Printf("易支付回调未找到订单: %v", verifyInfo)
214 return
215 }
216 if topUp.Status == "pending" {
217 topUp.Status = "success"
218 err := topUp.Update()
219 if err != nil {
220 log.Printf("易支付回调更新订单失败: %v", topUp)
221 return
222 }
223 //user, _ := model.GetUserById(topUp.UserId, false)
224 //user.Quota += topUp.Amount * 500000
225 dAmount := decimal.NewFromInt(int64(topUp.Amount))
226 dQuotaPerUnit := decimal.NewFromFloat(common.QuotaPerUnit)
227 quotaToAdd := int(dAmount.Mul(dQuotaPerUnit).IntPart())
228 err = model.IncreaseUserQuota(topUp.UserId, quotaToAdd, true)
229 if err != nil {
230 log.Printf("易支付回调更新用户失败: %v", topUp)
231 return
232 }
233 log.Printf("易支付回调更新用户成功 %v", topUp)
234 model.RecordLog(topUp.UserId, model.LogTypeTopup, fmt.Sprintf("使用在线充值成功,充值金额: %v,支付金额:%f", common.LogQuota(quotaToAdd), topUp.Money))
235 }

Callers

nothing calls this directly

Calls 9

GetTopUpByTradeNoFunction · 0.92
IncreaseUserQuotaFunction · 0.92
RecordLogFunction · 0.92
LogQuotaFunction · 0.92
GetEpayClientFunction · 0.85
LockOrderFunction · 0.85
UnlockOrderFunction · 0.85
GetMethod · 0.80
UpdateMethod · 0.45

Tested by

no test coverage detected