第三方api接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
4.0 KiB

  1. package yibao_pay
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db/offical"
  4. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  5. "encoding/json"
  6. "errors"
  7. "fmt"
  8. "github.com/yop-platform/yop-go-sdk/yop/client"
  9. "github.com/yop-platform/yop-go-sdk/yop/constants"
  10. "github.com/yop-platform/yop-go-sdk/yop/request"
  11. "github.com/yop-platform/yop-go-sdk/yop/response"
  12. "github.com/yop-platform/yop-go-sdk/yop/utils"
  13. "net/url"
  14. "os"
  15. "strings"
  16. "xorm.io/xorm"
  17. )
  18. func GetSend(method, appId, isvPriKey string, param map[string]string) (*response.YopResponse, error) {
  19. var priKey = request.IsvPriKey{Value: isvPriKey, CertType: request.RSA2048}
  20. var yopRequest = request.NewYopRequest(constants.GET_HTTP_METHOD, method)
  21. yopRequest.AppId = appId
  22. yopRequest.IsvPriKey = priKey
  23. for k, v := range param {
  24. yopRequest.AddParam(k, v)
  25. }
  26. yopResp, err := client.DefaultClient.Request(yopRequest)
  27. return yopResp, err
  28. }
  29. func PostFormSend(method, appId, isvPriKey string, param map[string]string) (*response.YopResponse, error) {
  30. var priKey = request.IsvPriKey{Value: isvPriKey, CertType: request.RSA2048}
  31. var yopRequest = request.NewYopRequest(constants.POST_HTTP_METHOD, method)
  32. yopRequest.AppId = appId
  33. yopRequest.IsvPriKey = priKey
  34. for k, v := range param {
  35. yopRequest.AddParam(k, v)
  36. }
  37. yopResp, err := client.DefaultClient.Request(yopRequest)
  38. return yopResp, err
  39. }
  40. func PostJsonSend(method, appId, isvPriKey string, params map[string]interface{}) (*response.YopResponse, error) {
  41. var priKey = request.IsvPriKey{Value: isvPriKey, CertType: request.RSA2048}
  42. var yopRequest = request.NewYopRequest(constants.POST_HTTP_METHOD, method)
  43. yopRequest.AppId = appId
  44. yopRequest.IsvPriKey = priKey
  45. yopRequest.Content = utils.ParseToJsonStr(params)
  46. yopResp, err := client.DefaultClient.Request(yopRequest)
  47. return yopResp, err
  48. }
  49. func FileUploadSend(method, appId, isvPriKey string, name string, f *os.File) (*response.YopResponse, error) {
  50. var priKey = request.IsvPriKey{Value: isvPriKey, CertType: request.RSA2048}
  51. var yopRequest = request.NewYopRequest(constants.POST_HTTP_METHOD, method)
  52. yopRequest.AppId = appId
  53. yopRequest.IsvPriKey = priKey
  54. yopRequest.AddFile(name, f)
  55. yopResp, err := client.DefaultClient.Request(yopRequest)
  56. return yopResp, err
  57. }
  58. func GetYibao(bodyStr string) (*YibaoJoinCallback, error) {
  59. decodeArgs, err := url.QueryUnescape(bodyStr)
  60. if err != nil {
  61. return nil, errors.New("失败")
  62. }
  63. data, err := url.ParseQuery(decodeArgs)
  64. if err != nil {
  65. return nil, err
  66. }
  67. dataMap := make(map[string]interface{})
  68. for k := range data {
  69. dataMap[k] = data.Get(k)
  70. }
  71. callbackStr := zhios_third_party_utils.SerializeStr(dataMap)
  72. callbackStr = strings.ReplaceAll(callbackStr, "\\r", "")
  73. callbackStr = strings.ReplaceAll(callbackStr, "\\n", "")
  74. fmt.Println("易宝回调数据", string(callbackStr))
  75. var args YibaoJoinCallback
  76. if err := json.Unmarshal([]byte(callbackStr), &args); err != nil {
  77. return nil, err
  78. }
  79. return &args, nil
  80. }
  81. func CommKey(eg *xorm.Engine, Prd bool) map[string]string {
  82. appId := offical.SysCfgByKeyStr(eg, "yibao_appid")
  83. isvPriKey := offical.SysCfgByKeyStr(eg, "yibao_key")
  84. parentMerchantNo := offical.SysCfgByKeyStr(eg, "yibao_merchant_no")
  85. zhiyingMerchantNo := offical.SysCfgByKeyStr(eg, "yibao_zhiying_merchant_no")
  86. zhiyingOnlineBili := offical.SysCfgByKeyStr(eg, "yibao_zhiying_online_bili")
  87. zhiyingUnlineBili := offical.SysCfgByKeyStr(eg, "yibao_zhiying_unline_bili")
  88. yibaoOnlineBili := offical.SysCfgByKeyStr(eg, "yibao_online_bili")
  89. yibaoUnlineBili := offical.SysCfgByKeyStr(eg, "yibao_unline_bili")
  90. if Prd == false {
  91. appId = offical.SysCfgByKeyStr(eg, "yibao_appid_test")
  92. isvPriKey = offical.SysCfgByKeyStr(eg, "yibao_key_test")
  93. }
  94. res := map[string]string{
  95. "zhiyingOnlineBili": zhiyingOnlineBili,
  96. "zhiyingUnlineBili": zhiyingUnlineBili,
  97. "yibaoOnlineBili": yibaoOnlineBili,
  98. "yibaoUnlineBili": yibaoUnlineBili,
  99. "appId": appId,
  100. "zhiyingMerchantNo": zhiyingMerchantNo,
  101. "isvPriKey": isvPriKey,
  102. "parentMerchantNo": parentMerchantNo,
  103. }
  104. return res
  105. }