service-multi-pay.go 997 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package api
  2. import (
  3. "fmt"
  4. "net/http"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func PayMulti(r *GinRouter) {
  8. r.POST("/multi/alipay/callback", MultiAliCallBack)
  9. r.POST("/multi/wechat/callback", MultiWechatCallBack)
  10. }
  11. func MultiAliCallBack(c *gin.Context, apictx *ApiSession) (interface{}, error) {
  12. fmt.Println(c)
  13. // 默认走阿里支付
  14. pay := PayMod(ALIPAY, MULTI)
  15. res, err := pay.CallBack(c.Request)
  16. if err != nil {
  17. return false, NewError(err.Error())
  18. }
  19. c.String(http.StatusOK, res.(string))
  20. return nil, nil
  21. }
  22. func MultiWechatCallBack(c *gin.Context, apictx *ApiSession) (interface{}, error) {
  23. // 微信回调
  24. pay := PayMod(WECHATPAY, MULTI)
  25. res, err := pay.CallBack(c.Request)
  26. if err != nil {
  27. // return false, NewError(err.Error())
  28. c.JSON(http.StatusOK, gin.H{"code": res, "message": err.Error()})
  29. }
  30. c.JSON(http.StatusOK, gin.H{"code": res, "message": "成功"})
  31. // c.JSON(http.StatusOK, &wechat.V3NotifyRsp{Code: res.(string), Message: err.Error()})
  32. return nil, nil
  33. }