插件-云闪付红包
This commit is contained in:
parent
fe66d8d3a7
commit
1fbf6e1e48
|
@ -0,0 +1,37 @@
|
|||
module plugins/union_pay_redpack
|
||||
|
||||
go 1.22.2
|
||||
|
||||
require (
|
||||
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6
|
||||
github.com/carlmjohnson/requests v0.23.4
|
||||
github.com/go-playground/validator/v10 v10.22.0
|
||||
github.com/hashicorp/go-plugin v1.6.1
|
||||
github.com/stretchr/testify v1.9.0
|
||||
github.com/tjfoc/gmsm v1.4.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/fatih/color v1.7.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/hashicorp/go-hclog v0.14.1 // indirect
|
||||
github.com/hashicorp/yamux v0.1.1 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.4 // indirect
|
||||
github.com/mattn/go-isatty v0.0.10 // indirect
|
||||
github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77 // indirect
|
||||
github.com/oklog/run v1.0.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
golang.org/x/crypto v0.21.0 // indirect
|
||||
golang.org/x/net v0.22.0 // indirect
|
||||
golang.org/x/sys v0.18.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
|
||||
google.golang.org/grpc v1.64.0 // indirect
|
||||
google.golang.org/protobuf v1.34.2 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
|
@ -0,0 +1,102 @@
|
|||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
gitea.cdlsxd.cn/BaseSystem/plugin v0.0.0-20240821033242-d9c3e7ad88f6/go.mod h1:59zYRFcPur2HizJEIfttVOMY0AscollDYKX0yvPJS7k=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/carlmjohnson/requests v0.23.4/go.mod h1:Qzp6tW4DQyainPP+tGwiJTzwxvElTIKm0B191TgTtOA=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
|
||||
github.com/hashicorp/go-plugin v1.6.1/go.mod h1:XPHFku2tFo3o3QKFgSYo+cghcUhw1NA1hZyMK0PWAw0=
|
||||
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
|
||||
github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
|
||||
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/tjfoc/gmsm v1.4.1/go.mod h1:j4INPkHWMrhJb38G+J6W4Tw0AbuN8Thu3PbdVYhVcTE=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
|
@ -0,0 +1,36 @@
|
|||
package po
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"plugins/union_pay_redpack/internal/vo"
|
||||
)
|
||||
|
||||
type OrderReq struct {
|
||||
ChNlId string `validate:"required" json:"chnlId"` // 渠道方代码-必填
|
||||
AccessId string `validate:"required" json:"accessId"`
|
||||
TransDtTm string `validate:"required" json:"transDtTm"`
|
||||
InsAcctTp string `validate:"required" json:"insAcctTp"`
|
||||
InsAcctId string `validate:"required" json:"insAcctId"`
|
||||
AcctEntityTp string `validate:"required" json:"acctEntityTp"`
|
||||
Mobile string `validate:"required" json:"mobile"`
|
||||
PointTp string `validate:"required" json:"pointTp"`
|
||||
PointId string `validate:"required" json:"pointId"`
|
||||
PointAt string `validate:"required" json:"pointAt"`
|
||||
DelayIn string `validate:"required" json:"delayIn"`
|
||||
TempIn string `validate:"required" json:"tempIn"`
|
||||
InOutTransFlag string `validate:"required" json:"inOutTransFlag"`
|
||||
TransDigest string `validate:"required" json:"transDigest"`
|
||||
}
|
||||
|
||||
type OrderResp struct {
|
||||
Code vo.Code `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
SubCode vo.SubCode `json:"subCode"`
|
||||
SubMsg string `json:"subMsg"`
|
||||
|
||||
TransSeq string `json:"transSeq"`
|
||||
}
|
||||
|
||||
func (o *OrderResp) GetMsg() string {
|
||||
return fmt.Sprintf("Msg:[%s],SubMsg:[%s],自定处理msg:[%s]", o.Msg, o.SubMsg, o.SubCode.GetMsg())
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package po
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
type Req interface {
|
||||
Validate() error
|
||||
ToJson() []byte
|
||||
}
|
||||
|
||||
var _ Req = (*OrderReq)(nil)
|
||||
var _ Req = (*QueryReq)(nil)
|
||||
|
||||
func (req *OrderReq) Validate() error {
|
||||
err := validator.New().Struct(req)
|
||||
if err != nil {
|
||||
for _, err = range err.(validator.ValidationErrors) {
|
||||
return fmt.Errorf("参数有误:" + err.Error())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (req *OrderReq) ToJson() []byte {
|
||||
b, _ := json.Marshal(req)
|
||||
return b
|
||||
}
|
||||
|
||||
func (req *QueryReq) Validate() error {
|
||||
err := validator.New().Struct(req)
|
||||
if err != nil {
|
||||
for _, err = range err.(validator.ValidationErrors) {
|
||||
return fmt.Errorf("参数有误:" + err.Error())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (req *QueryReq) ToJson() []byte {
|
||||
b, _ := json.Marshal(req)
|
||||
return b
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package po
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"plugins/union_pay_redpack/internal/vo"
|
||||
)
|
||||
|
||||
type QueryReq struct {
|
||||
ChNlId string `validate:"required" json:"chnlId"` // 渠道方代码-必填
|
||||
TransSeq string `validate:"required" json:"transSeq"`
|
||||
TransDtTm string `validate:"required" json:"transDtTm"`
|
||||
OrigTransSeq string `validate:"required" json:"origTransSeq"`
|
||||
OrigTransDtTm string `validate:"required" json:"origTransDtTm"`
|
||||
AcctEntityTp string `validate:"required" json:"acctEntityTp"`
|
||||
Mobile string `validate:"required" json:"mobile"`
|
||||
}
|
||||
|
||||
type QueryResp struct {
|
||||
Code vo.Code `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
SubCode vo.SubCode `json:"subCode"`
|
||||
SubMsg string `json:"subMsg"`
|
||||
|
||||
TransSeq string `json:"transSeq"`
|
||||
AcquireSt vo.AcquireSt `json:"acquireSt"`
|
||||
}
|
||||
|
||||
func (o *QueryResp) GetMsg() string {
|
||||
return fmt.Sprintf("Msg:[%s],SubMsg:[%s],自定处理msg:[%s]", o.Msg, o.SubMsg, o.SubCode.GetMsg())
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"gitea.cdlsxd.cn/BaseSystem/plugin/proto"
|
||||
"plugins/union_pay_redpack/internal/po"
|
||||
"plugins/union_pay_redpack/internal/utils"
|
||||
"plugins/union_pay_redpack/internal/vo"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
AppId string `json:"app_id"`
|
||||
BaseUri string `json:"base_uri"`
|
||||
|
||||
ChNlId string `json:"chnlId"` // 渠道方代码
|
||||
IV string `json:"iv"` // 加密密钥
|
||||
KEY string `json:"key"` // 加密密钥
|
||||
Prk string `json:"prk"` // 私钥
|
||||
Npk string `json:"npk"` // 回调公钥
|
||||
}
|
||||
|
||||
func transConfig(config []byte) (*Config, error) {
|
||||
var c Config
|
||||
err := json.Unmarshal(config, &c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
func (c *Config) orderReq(in *proto.OrderRequest) (*po.OrderReq, error) {
|
||||
type OrderExtra struct {
|
||||
OrderDt string `json:"orderDt"`
|
||||
}
|
||||
var e OrderExtra
|
||||
_ = json.Unmarshal(in.Order.Extra, &e)
|
||||
|
||||
mobile, err := utils.Encrypt([]byte(in.Order.Account), []byte(c.KEY), []byte(c.IV))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &po.OrderReq{
|
||||
ChNlId: c.ChNlId,
|
||||
AccessId: vo.AccessId,
|
||||
TransDtTm: "",
|
||||
InsAcctTp: "",
|
||||
InsAcctId: "",
|
||||
AcctEntityTp: "",
|
||||
Mobile: mobile,
|
||||
PointTp: "",
|
||||
PointId: "",
|
||||
PointAt: "",
|
||||
DelayIn: "",
|
||||
TempIn: "",
|
||||
InOutTransFlag: "",
|
||||
TransDigest: "",
|
||||
}, nil
|
||||
}
|
||||
|
||||
func orderResp(request *proto.OrderRequest, resp po.OrderResp) *proto.OrderResponse {
|
||||
data, _ := json.Marshal(resp)
|
||||
result := &proto.Result{
|
||||
OrderNo: request.Order.OrderNo,
|
||||
TradeNo: resp.TransSeq,
|
||||
Message: resp.Msg,
|
||||
Data: data,
|
||||
}
|
||||
if !resp.Code.IsSuccess() {
|
||||
result.Status = proto.Status_FAIL
|
||||
result.Message = resp.GetMsg()
|
||||
} else {
|
||||
result.Status = proto.Status_ING
|
||||
}
|
||||
return &proto.OrderResponse{Result: result}
|
||||
}
|
||||
|
||||
func queryReq(in *proto.QueryRequest, chNlId string) *po.QueryReq {
|
||||
type OrderExtra struct {
|
||||
OrigDate string `json:"origDate"`
|
||||
}
|
||||
var e OrderExtra
|
||||
_ = json.Unmarshal(in.Order.Extra, &e)
|
||||
return &po.QueryReq{
|
||||
ChNlId: chNlId,
|
||||
TransSeq: "",
|
||||
TransDtTm: "",
|
||||
OrigTransSeq: "",
|
||||
OrigTransDtTm: "",
|
||||
AcctEntityTp: "",
|
||||
Mobile: "",
|
||||
}
|
||||
}
|
||||
|
||||
func queryResp(request *proto.QueryRequest, resp po.QueryResp) *proto.QueryResponse {
|
||||
data, _ := json.Marshal(resp)
|
||||
result := &proto.Result{
|
||||
OrderNo: request.Order.OrderNo,
|
||||
TradeNo: request.Order.TradeNo,
|
||||
Status: resp.AcquireSt.GetOrderStatus(),
|
||||
Message: resp.GetMsg(),
|
||||
Data: data,
|
||||
}
|
||||
return &proto.QueryResponse{Result: result}
|
||||
}
|
||||
|
||||
func notifyResp() *proto.NotifyResponse {
|
||||
result := &proto.Result{
|
||||
Status: proto.Status_ING,
|
||||
OrderNo: "",
|
||||
TradeNo: "",
|
||||
Message: "无回调通知",
|
||||
Data: nil,
|
||||
Extra: nil,
|
||||
}
|
||||
return &proto.NotifyResponse{Result: result}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"gitea.cdlsxd.cn/BaseSystem/plugin/proto"
|
||||
"github.com/carlmjohnson/requests"
|
||||
"plugins/union_pay_redpack/internal/po"
|
||||
)
|
||||
|
||||
// 插件通信信息,若不对应则会报错panic
|
||||
const (
|
||||
Tag = "union_pay_redpack"
|
||||
Version = 1
|
||||
CookieKey = "union_pay_redpack"
|
||||
CookieValue = "union_pay_redpack"
|
||||
)
|
||||
|
||||
const (
|
||||
orderMethod = "/upapi/mkt/pnt/pntAcquire/v1"
|
||||
orderBizMethod = "mkt.pnt.pntAcquire.v1"
|
||||
)
|
||||
|
||||
const (
|
||||
queryMethod = "/upapi/mkt/pnt/pntAcqQuery/v1"
|
||||
queryBizMethod = "mkt.pnt.pntAcqQuery.v1"
|
||||
)
|
||||
|
||||
type UnionPayCpnService struct{}
|
||||
|
||||
func (p *UnionPayCpnService) Order(ctx context.Context, request *proto.OrderRequest) (*proto.OrderResponse, error) {
|
||||
c, err := transConfig(request.Config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uv, err := c.orderReq(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = uv.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response po.OrderResp
|
||||
url := fmt.Sprintf("%s%s", c.BaseUri, orderMethod)
|
||||
err = requests.URL(url).Headers(headers(c, uv, orderBizMethod)).BodyJSON(uv).ToJSON(&response).Fetch(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||
}
|
||||
|
||||
return orderResp(request, response), nil
|
||||
}
|
||||
|
||||
func (p *UnionPayCpnService) Query(ctx context.Context, request *proto.QueryRequest) (*proto.QueryResponse, error) {
|
||||
conf, err := transConfig(request.Config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uv := queryReq(request, conf.ChNlId)
|
||||
if err = uv.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response po.QueryResp
|
||||
url := fmt.Sprintf("%s%s", conf.BaseUri, queryMethod)
|
||||
err = requests.URL(url).Headers(headers(conf, uv, queryBizMethod)).BodyJSON(uv).ToJSON(&response).Fetch(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||
}
|
||||
|
||||
return queryResp(request, response), nil
|
||||
}
|
||||
|
||||
func (p *UnionPayCpnService) Notify(_ context.Context, _ *proto.NotifyRequest) (*proto.NotifyResponse, error) {
|
||||
return notifyResp(), nil
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gitea.cdlsxd.cn/BaseSystem/plugin/proto"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func config() []byte {
|
||||
c := &Config{
|
||||
AppId: "up_49pau3fu6latj_03h",
|
||||
BaseUri: "https://openapi.unionpay.com",
|
||||
ChNlId: "8091",
|
||||
IV: "0123456789123456",
|
||||
KEY: "16fb034dead44ff6f599b1ca373ccfd1",
|
||||
Prk: "MIIEogIBAAKCAQEAllAo3AbVfNg1iDT3CisgueIm2Pya2C6qatF0S8/aAKW8A6HBIuvrk1sb2TjbI0UDVowaNDsPa7nNdZHkQa6CQKf2BwFRy7gB8vAD1YSq23NTwplGe5IpuRe2Cbljh5diQ/+0zwZPZQEvjSMqZJILYVluGBw656JSndRdXHCs608CBib14l35A6D7rSZNd53nM9yXj/WOpLuY/jX0sbKJrBUIhcQcMiCFK/Nx06vhhCGZSWwaj0TTSMEOj9nyU+56MMx+N7527JUnOYMyVbbEx5h1S5sPjntMVVzz8c8FC5MKbgXCgjTt5Depl6YgrvoSCNNXZqnXN2l9dtBxKGSEdQIDAQABAoIBAD7r606/pZqPP0l3MnqVNyvY2X43r/ITBs+UQmSB67Ydqqiyi5C8xW530x6JSGJpP055c3atynTD4Jf4rF46WNgL91dTXBQ1QMubYV9+G6+lhUiOtQyBUOnkXRWQ/3MBEed5IQ0QjSew6WDheZuD7zOfJhD9sELKll7vSO2rVRdi5Kf3pps0K4aeYLvlelHjPtu2EkMyAD4d37QO2q8A/+acOf7wyx1uZ55nobe0jVgQBa2Tuuwhd2JilmsgMvcVxeAJoocyQxPVTU+iMidgZKxyW/fJUaR7V2KgKfP0H2OZbSruD2HyHL7o70+/XBg250msh691oTCXSGWiITFXRDkCgYEA1KF3daSzWK2vTZeNMxj++VRNZfyigNqBwgRZxrSGIUeNGpDdDp7flldM/fO/0RijKnh+nXLBCMZlxffSI7W3jkkjosEq0uyXv6Ez4WlhwHEAE6KrZYQ8VDU3We1LXERu/3SMU16Uq2Vme8J6kpshr7OLGeuTNfsSG79lpHU/OO8CgYEAtPjF/AY/t85u4JV0w6FJ/K7Iya+AyIyZhsgnxsPv5NwVtNsQzTRbXlpgnVmaKUXzLBTBJA2P6Gie35R6kJuOuMnvHjtG7umI5lOUJaqYk5GZEXHxbIKTXUxAbv+WKRHcFwcH54Ppurs7bN6ultWdE+yyU5PvabFRAidL+rV+MNsCgYBkqx2XwSZ4MaLxpXLgYlE1UkhipL17K/iLFuw6O3XVg762eSdvqKBK2YJGKYUDRhraHLo1aQMjWGsO00nWRk5lOxN4FuRjgEhIHdYmPnJdXiKfKUDkizrU020lUkd/o5a5s0BMqFbS3usqZOULTA8i1GpjFzlXMUtdf7xrpGcOWQKBgFJXWuX4Befg8owXFKCqc1qYQF2cEBGv/27XBVon7rAH/4xhnHxx1RzSLGGL0lvzKtikvNhln1PUvmzmRvoi/UZRAw6TVAwCkDqUTrTwsSl7ttS8Lmf75Ycu2aZnfnBDYwvLNCp/18oRxNEdZPzWRvk42k6y4d0KQ9yh+q0hBUC/AoGASgJro5HgKWkSzYx1Fk3rvo7EWeZwXNfWuzIhtCiVDG4+df0ZdybkbjxbaRwL2rbTSBeqSaZw4UwpE1JyF8erfzx0qpHCY5V3ocnA8kg56mX9kE5H9WKjMe1tbuZpba4i08zvM8vpz9gASf3z/WrWWqgpvynxDWpy4xFAqrWC0VQ=",
|
||||
Npk: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy05sCMKEYZQGryKKq7qxxMi4uIRcOuv0aQcptjEifc/TS56bU0iGlkuH9k90tPp6EoKYLUfnL1FdHQOWXboFktwoxjy372gc6CsQfU9ZNjsWMYI8CTZF6gWLk4HjfBO4HcCKJs7oGntgVZxfVqVxJ8N/M1ZC2sDuVkoHYymONgNwgO+yYXrAlPPfJBltG5QNOcGTHBZ4PTc6A0M17+2BiskKUJfLEbN2soEZR0b5v5qy0D1xe5w+CdNcvtEb5CemPRxxRYjIqfHlhQPO7ZCUFPmhtoIbtBYG+BIU+qK3Q1DDiBndOVkQGVBQcOnMfYpxp82hlA1TAVeRICWubH3nJwIDAQAB",
|
||||
}
|
||||
marshal, _ := json.Marshal(c)
|
||||
return marshal
|
||||
}
|
||||
|
||||
var server = &UnionPayCpnService{}
|
||||
|
||||
func TestOrder(t *testing.T) {
|
||||
request := &proto.OrderRequest{
|
||||
Config: config(),
|
||||
Order: &proto.OrderRequest_Order{
|
||||
OrderNo: "240403164049635931",
|
||||
Account: "13100720242", // R2wVgntY8aP9QTvCN/bWfw==
|
||||
Quantity: 1,
|
||||
Extra: []byte(`{"orderDt":"20240704"}`),
|
||||
},
|
||||
Product: &proto.OrderRequest_Product{
|
||||
ProductNo: "3102024032977191",
|
||||
Extra: []byte(`{}`),
|
||||
},
|
||||
}
|
||||
t.Run("TestOrder", func(t *testing.T) {
|
||||
got, err := server.Order(context.Background(), request)
|
||||
if err != nil {
|
||||
t.Errorf("Order() error = %v", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("%+v", got)
|
||||
assert.Equal(t, int(proto.Status_ING), int(got.Result.Status))
|
||||
})
|
||||
}
|
||||
|
||||
func TestQuery(t *testing.T) {
|
||||
request := &proto.QueryRequest{
|
||||
Config: config(),
|
||||
Order: &proto.QueryRequest_Order{
|
||||
OrderNo: "240403164049635931",
|
||||
TradeNo: "",
|
||||
Account: "",
|
||||
Extra: []byte(`{"origDate":"20240704"}`),
|
||||
},
|
||||
}
|
||||
t.Run("TestQuery", func(t *testing.T) {
|
||||
got, err := server.Query(context.Background(), request)
|
||||
if err != nil {
|
||||
t.Errorf("Query() error = %v", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("%+v \n", got)
|
||||
assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status))
|
||||
})
|
||||
}
|
||||
|
||||
func TestNotify(t *testing.T) {
|
||||
in := &proto.NotifyRequest{
|
||||
Config: config(),
|
||||
Queries: nil,
|
||||
Headers: []byte(`{"bizmethod":"mkt.CpnStateUpdtNotify","apptype":"00","appid":"up_49pau3fu6latj_03h","sign":"F1WQAg3CRdXsBE+1dmAy+ulNkxFWDRkI6Q\/5xcpC\/bOCbcEFeun536hfhU0In+e+5GHPbfpIqyZjjglTm60QvSwvutqOiVlEBy\/G4GpIJPuLy6hdzy9Z+f56qSa0wzIjSxKqG1VuaFd2uS4WzSrx8E6hdPotXkuKzdcRwCCq\/wlmFPVxRRIVNTf6KgqkX4aNsC\/MGdLN9E5DOfoFdC8+oPqV5N71i6SjLvrzo4yaGJm+utSqEORsWZLgfZLUw+pZGjS83rQpFEKC5UyL6KwbIefNJ7a\/5cykiNIGzTRR9Tzz+UxuoiVglJ4AeUb2vs0rL8SoUjr8aLAAqPcXzPE5wQ==","reqts":"1690252684000","version":"1.0.0","signmethod":"RSA2","reqid":"8091_lsxd6688-10","content-type":"application/json"}`),
|
||||
Body: []byte(`{"couponNum":"1","traceId":"lsxd6688-10","OperTp":"","chnlId":"9001","transChnl":"","couponNm":"众邦银行1元立减-测试","operTp":"04","couponCd":"INNER_23072510380403358473638771025186","couponId":"3102023071900090","orderAt":"0","transSeq":"lsxd6688-10","posTmn":"","discountAt":"0","couponCdInfos":[{"subAcctOperAt":"1","couponCd":"INNER_23072510380403358473638771025186"}],"mchntCd":"","transDtTm":"20230725103804"}`),
|
||||
}
|
||||
t.Run("TestNotify", func(t *testing.T) {
|
||||
got, err := server.Notify(context.Background(), in)
|
||||
if err != nil {
|
||||
t.Errorf("Notify() error = %v", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("TestNotify : %+v \n", got)
|
||||
assert.Equal(t, int(proto.Status_SUCCESS), int(got.Result.Status))
|
||||
})
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
sdkutils "gitea.cdlsxd.cn/BaseSystem/plugin/utils"
|
||||
"net/http"
|
||||
"plugins/union_pay_redpack/internal/po"
|
||||
"plugins/union_pay_redpack/internal/utils"
|
||||
"plugins/union_pay_redpack/internal/vo"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func headers(config *Config, req po.Req, bizMethod string) map[string][]string {
|
||||
h := make(http.Header)
|
||||
h.Add("Content-type", vo.ContentType)
|
||||
h.Add("version", vo.Version)
|
||||
h.Add("appType", vo.AppType)
|
||||
h.Add("signMethod", vo.SignMethod)
|
||||
|
||||
h.Add("appId", config.AppId)
|
||||
h.Add("bizMethod", bizMethod)
|
||||
|
||||
h.Add("reqId", req.GetReId())
|
||||
|
||||
now := time.Now()
|
||||
milliseconds := now.Unix()*1000 + int64(now.Nanosecond())/1e6
|
||||
h.Add("reqTs", fmt.Sprintf("%d", milliseconds))
|
||||
|
||||
rehash := utils.Sha(vo.Version, config.AppId, bizMethod, req.GetReId(), string(req.ToJson()))
|
||||
signValue, err := utils.Sign(rehash, []byte(sdkutils.NewPrivate().Build(config.Prk)))
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
h.Add("sign", signValue)
|
||||
return h
|
||||
}
|
||||
|
||||
func verify(config *Config, req *po.Notify, notifyBizMethod string) error {
|
||||
if req.Headers.SignMethod != vo.SignMethod {
|
||||
return fmt.Errorf("签名方式不匹配")
|
||||
}
|
||||
if req.Headers.AppId != config.AppId {
|
||||
return fmt.Errorf("appId不匹配")
|
||||
}
|
||||
if req.Headers.BizMethod != notifyBizMethod {
|
||||
return fmt.Errorf("业务方法不匹配")
|
||||
}
|
||||
rehash := utils.Sha(req.Headers.Version, config.AppId, req.Headers.BizMethod, req.GetReId(), string(req.ToJson()))
|
||||
lowerStr := strings.ToLower(rehash)
|
||||
if utils.Verify(lowerStr, req.Headers.Sign, []byte(sdkutils.NewPublic().Build(config.Npk))) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("验签失败")
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func Sha(version, appId, bizMethod, reId, body string) string {
|
||||
s := fmt.Sprintf("version=%s&appId=%s&bizMethod=%s&reqId=%s&body=%s", version, appId, bizMethod, reId, body)
|
||||
return encodeBySHA256([]byte(s))
|
||||
}
|
||||
|
||||
func encodeBySHA256(str []byte) string {
|
||||
hash := sha256.Sum256(str)
|
||||
return getFormattedText(hash[:])
|
||||
}
|
||||
|
||||
func getFormattedText(bytes []byte) string {
|
||||
HexDigits := "0123456789abcdef"
|
||||
|
||||
l := len(bytes)
|
||||
buf := make([]byte, l*2)
|
||||
for j := 0; j < l; j++ {
|
||||
buf[j*2] = HexDigits[(bytes[j]>>4)&0x0f]
|
||||
buf[j*2+1] = HexDigits[bytes[j]&0x0f]
|
||||
}
|
||||
|
||||
return string(buf)
|
||||
}
|
||||
|
||||
func ConvertToInt(value interface{}) int {
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
if intValue, err := strconv.Atoi(v); err == nil {
|
||||
return intValue
|
||||
}
|
||||
case int:
|
||||
return v
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// HexToBytes 将16进制的字符数组转换成byte数组
|
||||
func HexToBytes(hex []byte) []byte {
|
||||
length := len(hex) / 2
|
||||
raw := make([]byte, length)
|
||||
for i := 0; i < length; i++ {
|
||||
high, _ := strconv.ParseInt(string(hex[i*2]), 16, 0)
|
||||
low, _ := strconv.ParseInt(string(hex[i*2+1]), 16, 0)
|
||||
value := int(high<<4) | int(low)
|
||||
if value > 127 {
|
||||
value -= 256
|
||||
}
|
||||
raw[i] = byte(value)
|
||||
}
|
||||
return raw
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/sha256"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func Sign(data string, privateKeyPEM []byte) (string, error) {
|
||||
block, _ := pem.Decode(privateKeyPEM)
|
||||
if block == nil {
|
||||
return "", errors.New("failed to parse PEM block containing the private key")
|
||||
}
|
||||
|
||||
privyKey, err := x509.ParsePKCS1PrivateKey(block.Bytes)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to parse DER encoded private key: %v", err)
|
||||
}
|
||||
|
||||
hashed := sha256.Sum256([]byte(data))
|
||||
signature, err := rsa.SignPKCS1v15(rand.Reader, privyKey, crypto.SHA256, hashed[:])
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to sign: %v", err)
|
||||
}
|
||||
|
||||
return base64.StdEncoding.EncodeToString(signature), nil
|
||||
}
|
||||
|
||||
func Verify(data, signature string, publicKeyPEM []byte) bool {
|
||||
block, _ := pem.Decode(publicKeyPEM)
|
||||
if block == nil {
|
||||
fmt.Println("failed to parse PEM block containing the public key")
|
||||
return false
|
||||
}
|
||||
|
||||
pubKey, err := x509.ParsePKIXPublicKey(block.Bytes)
|
||||
if err != nil {
|
||||
fmt.Println("error parsing public key:", err)
|
||||
return false
|
||||
}
|
||||
|
||||
rsaPubKey, ok := pubKey.(*rsa.PublicKey)
|
||||
if !ok {
|
||||
fmt.Println("not an RSA public key")
|
||||
return false
|
||||
}
|
||||
|
||||
hashed := sha256.Sum256([]byte(data))
|
||||
sig, err := base64.StdEncoding.DecodeString(signature)
|
||||
if err != nil {
|
||||
fmt.Println("error decoding signature:", err)
|
||||
return false
|
||||
}
|
||||
|
||||
err = rsa.VerifyPKCS1v15(rsaPubKey, crypto.SHA256, hashed[:], sig)
|
||||
if err != nil {
|
||||
fmt.Println("signature verification error:", err)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"github.com/tjfoc/gmsm/sm4"
|
||||
)
|
||||
|
||||
func Encrypt(txt, key, iv []byte) (string, error) {
|
||||
pk := HexToBytes(key)
|
||||
|
||||
err := sm4.SetIV(iv)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("sm4.SetIV err:%v", err)
|
||||
}
|
||||
cipherTxt, err := sm4.Sm4Cbc(pk, txt, true)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("sm4.Sm4Cbc err:%v", err)
|
||||
}
|
||||
|
||||
return base64.StdEncoding.EncodeToString(cipherTxt), nil
|
||||
}
|
||||
|
||||
func Decrypt(txt string, key []byte, iv []byte) (string, error) {
|
||||
plainText, err := base64.StdEncoding.DecodeString(txt)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("base64.StdEncoding.DecodeString err:%v", err)
|
||||
}
|
||||
pk := HexToBytes(key)
|
||||
|
||||
err = sm4.SetIV(iv)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("sm4.SetIV err:%v", err)
|
||||
}
|
||||
cipherTxt, err := sm4.Sm4Cbc(pk, plainText, false)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("sm4.Sm4Cbc err:%v", err)
|
||||
}
|
||||
|
||||
return string(cipherTxt), nil
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package vo
|
||||
|
||||
import "gitea.cdlsxd.cn/BaseSystem/plugin/proto"
|
||||
|
||||
type AcquireSt string
|
||||
|
||||
const (
|
||||
AcquireStSuccess AcquireSt = "10000"
|
||||
AcquireStFail AcquireSt = "20000"
|
||||
)
|
||||
|
||||
var notifyOrderTextMap = map[AcquireSt]string{
|
||||
AcquireStSuccess: "赠送成功",
|
||||
AcquireStFail: "赠送失败",
|
||||
}
|
||||
|
||||
var notifyOrderStatusMap = map[AcquireSt]proto.Status{
|
||||
AcquireStSuccess: proto.Status_SUCCESS,
|
||||
AcquireStFail: proto.Status_FAIL,
|
||||
}
|
||||
|
||||
func (o AcquireSt) GetText() string {
|
||||
msg, ok := notifyOrderTextMap[o]
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
func (o AcquireSt) GetOrderStatus() proto.Status {
|
||||
if o == "" {
|
||||
return proto.Status_INVALID
|
||||
}
|
||||
if resultStatus, ok := notifyOrderStatusMap[o]; ok {
|
||||
return resultStatus
|
||||
}
|
||||
return proto.Status_FAIL
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package vo
|
||||
|
||||
type Code string
|
||||
|
||||
const CodeSuccess Code = "0000000000"
|
||||
|
||||
func (c Code) IsSuccess() bool {
|
||||
return c == CodeSuccess
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package vo
|
||||
|
||||
const (
|
||||
ContentType = "application/json"
|
||||
Version = "1.0.0"
|
||||
AppType = "01"
|
||||
SignMethod = "RSA2"
|
||||
)
|
||||
|
||||
const (
|
||||
AccessId = "UP"
|
||||
EntityTp = "03"
|
||||
InsAcctTp = "UP23"
|
||||
AcctEntityTp = "UP01"
|
||||
PointTp = "41"
|
||||
DelayIn = "0"
|
||||
TempIn = "0"
|
||||
InOutTransFlag = "0"
|
||||
)
|
|
@ -0,0 +1,109 @@
|
|||
package vo
|
||||
|
||||
type SubCode string
|
||||
|
||||
const (
|
||||
SubCodeUp02094 SubCode = "UP02094"
|
||||
SubCodeUp02099 SubCode = "UP02099"
|
||||
SubCodeUp06003 SubCode = "UP06003"
|
||||
SubCodeUp06004 SubCode = "UP06004"
|
||||
SubCodeUp06005 SubCode = "UP06005"
|
||||
SubCodeUp06006 SubCode = "UP06006"
|
||||
SubCodeUp06007 SubCode = "UP06007"
|
||||
SubCodeUp06008 SubCode = "UP06008"
|
||||
SubCodeUp06009 SubCode = "UP06009"
|
||||
SubCodeUp06010 SubCode = "UP06010"
|
||||
SubCodeUp06011 SubCode = "UP06011"
|
||||
SubCodeUp06012 SubCode = "UP06012"
|
||||
SubCodeUp06021 SubCode = "UP06021"
|
||||
SubCodeUp06022 SubCode = "UP06022"
|
||||
SubCodeUp06034 SubCode = "UP06034"
|
||||
SubCodeUp06035 SubCode = "UP06035"
|
||||
SubCodeUp06036 SubCode = "UP06036"
|
||||
SubCodeUp06037 SubCode = "UP06037"
|
||||
SubCodeUp06038 SubCode = "UP06038"
|
||||
SubCodeUp06039 SubCode = "UP06039"
|
||||
SubCodeUp06040 SubCode = "UP06040"
|
||||
SubCodeUp06041 SubCode = "UP06041"
|
||||
SubCodeUp06042 SubCode = "UP06042"
|
||||
SubCodeUp06043 SubCode = "UP06043"
|
||||
SubCodeUp06044 SubCode = "UP06044"
|
||||
SubCodeUp06045 SubCode = "UP06045"
|
||||
SubCodeUp07001 SubCode = "UP07001"
|
||||
SubCodeUp07002 SubCode = "UP07002"
|
||||
SubCodeUp07003 SubCode = "UP07003"
|
||||
SubCodeUp07004 SubCode = "UP07004"
|
||||
SubCodeUp07005 SubCode = "UP07005"
|
||||
SubCodeUp07010 SubCode = "UP07010"
|
||||
SubCodeUp07012 SubCode = "UP07012"
|
||||
SubCodeUp07013 SubCode = "UP07013"
|
||||
SubCodeUp07014 SubCode = "UP07014"
|
||||
SubCodeUp07015 SubCode = "UP07015"
|
||||
SubCodeUp07020 SubCode = "UP07020"
|
||||
SubCodeUp07030 SubCode = "UP07030"
|
||||
SubCodeUp07050 SubCode = "UP07050"
|
||||
SubCodeUp07051 SubCode = "UP07051"
|
||||
SubCodeUp07052 SubCode = "UP07052"
|
||||
SubCodeUp00030 SubCode = "UP00030"
|
||||
SubCodeUp00050 SubCode = "UP00050"
|
||||
SubCodeUp00080 SubCode = "UP00080"
|
||||
SubCodeUp02025 SubCode = "UP02025"
|
||||
SubCodeUp02071 SubCode = "UP02071"
|
||||
)
|
||||
|
||||
var codeMsg = map[SubCode]string{
|
||||
SubCodeUp02094: "交易重复",
|
||||
SubCodeUp02099: "交易单品信息无效",
|
||||
SubCodeUp06003: "线上折扣活动不存在",
|
||||
SubCodeUp06004: "线上折扣活动已下线",
|
||||
SubCodeUp06005: "线上折扣活动未开始",
|
||||
SubCodeUp06006: "线上折扣活动已结束",
|
||||
SubCodeUp06007: "线上折扣活动已过期(当前消费请求已不满足)",
|
||||
SubCodeUp06008: "线上折扣活动多方出资配置或者计算错误",
|
||||
SubCodeUp06009: "线上折扣活动查询结果不满足消费请求(适用于查询并承兑)",
|
||||
SubCodeUp06010: "折扣活动承兑金额检验错误",
|
||||
SubCodeUp06011: "线上折扣活动余额不足",
|
||||
SubCodeUp06012: "线上折扣活动当前周期余额不足",
|
||||
SubCodeUp06021: "线上折扣活动城市校验失败,定位城市非活动城市",
|
||||
SubCodeUp06022: "线上折扣活动城市校验失败,交易未上送定位城市",
|
||||
SubCodeUp06034: "线上折扣活动参与卡付失败封顶",
|
||||
SubCodeUp06035: "线上折扣活动参与手机封顶",
|
||||
SubCodeUp06036: "线上折扣活动参与银行卡封顶",
|
||||
SubCodeUp06037: "线上折扣活动参与迷你付终端封顶",
|
||||
SubCodeUp06038: "线上折扣活动参与用户封顶",
|
||||
SubCodeUp06039: "线上折扣活动参与账单号封顶",
|
||||
SubCodeUp06040: "线上折扣活动参与用户商品数量封顶",
|
||||
SubCodeUp06041: "线上折扣活动参与证件号封顶",
|
||||
SubCodeUp06042: "线上折扣活动参与商户号封顶",
|
||||
SubCodeUp06043: "线上折扣活动参与人脸证件号封顶",
|
||||
SubCodeUp06044: "线上折扣活动参与商户Pos终端封顶",
|
||||
SubCodeUp06045: "线上折扣活动参与活动封顶",
|
||||
SubCodeUp07001: "优惠券下载失败",
|
||||
SubCodeUp07002: "优惠券冻结失败",
|
||||
SubCodeUp07003: "优惠券删除失败",
|
||||
SubCodeUp07004: "优惠券操作结果查询失败",
|
||||
SubCodeUp07005: "优惠券开放平台权限校验失败",
|
||||
SubCodeUp07010: "用户优惠券张数超过限制",
|
||||
SubCodeUp07012: "优惠券下载封顶累计失败",
|
||||
SubCodeUp07013: "优惠券下载调用账务失败",
|
||||
SubCodeUp07014: "优惠券下载卡号反查用户ID失败",
|
||||
SubCodeUp07015: "优惠券下载手机号反查用户ID失败",
|
||||
SubCodeUp07020: "优惠券冻结调用账务失败",
|
||||
SubCodeUp07030: "优惠券删除调用账户失败",
|
||||
SubCodeUp07050: "优惠券下载维度无效",
|
||||
SubCodeUp07051: "用户送券维度:当前用户未实名认证",
|
||||
SubCodeUp07052: "用户送券维度:可用银行卡与当前账户不同名,需绑定同名卡",
|
||||
SubCodeUp00030: "请求报文错误(无效)",
|
||||
SubCodeUp00050: "线上折扣系统并发控制限制",
|
||||
SubCodeUp00080: "线上折扣系统内部错误",
|
||||
SubCodeUp02025: "原交易不存在",
|
||||
SubCodeUp02071: "交易无效",
|
||||
}
|
||||
|
||||
func (code SubCode) GetMsg() string {
|
||||
msg, ok := codeMsg[code]
|
||||
if !ok {
|
||||
return "未知错误代码"
|
||||
}
|
||||
return msg
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"gitea.cdlsxd.cn/BaseSystem/plugin/shared"
|
||||
"github.com/hashicorp/go-plugin"
|
||||
"plugins/union_pay_redpack/internal"
|
||||
)
|
||||
|
||||
func main() {
|
||||
plugin.Serve(&plugin.ServeConfig{
|
||||
HandshakeConfig: shared.HandshakeConfig(internal.Version, internal.CookieKey, internal.CookieValue),
|
||||
Plugins: shared.PluginSet(shared.NewPlugin(&internal.UnionPayCpnService{}, internal.Tag)),
|
||||
GRPCServer: plugin.DefaultGRPCServer,
|
||||
})
|
||||
}
|
|
@ -2,7 +2,13 @@ package internal
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/services/transferbatch"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/utils"
|
||||
"log"
|
||||
"plugins/utils/weixin"
|
||||
)
|
||||
|
||||
|
@ -16,14 +22,70 @@ func transferBatchApiService(ctx context.Context, c *weixin.Server) (*transferba
|
|||
}
|
||||
|
||||
func transferDetailApiService(ctx context.Context, c *weixin.Server) (*transferbatch.TransferDetailApiService, error) {
|
||||
client, err := weixin.GetClient(ctx, c)
|
||||
cl()
|
||||
return nil, fmt.Errorf("----")
|
||||
mchPrivateKey, err := utils.LoadPrivateKeyWithPath(c.PrivateKeyPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("MchID[%s] load merchant private key error:%v", c.MchID, err)
|
||||
}
|
||||
opts := []core.ClientOption{
|
||||
option.WithWechatPayAutoAuthCipher(c.MchID, c.MchCertificateSerialNumber, mchPrivateKey, c.MchAPIv3Key),
|
||||
}
|
||||
if c.CertificatePath != "" {
|
||||
payCert, err := utils.LoadCertificateWithPath(c.CertificatePath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("MchID[%s] load pay certificate error:%v", c.MchID, err)
|
||||
}
|
||||
opts = append(opts, option.WithWechatPayCertificate([]*x509.Certificate{payCert}))
|
||||
}
|
||||
client, err := core.NewClient(ctx, opts...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("MchID[%s] %v", c.MchID, err)
|
||||
}
|
||||
|
||||
svc := transferbatch.TransferDetailApiService{Client: client}
|
||||
return &svc, nil
|
||||
}
|
||||
|
||||
func cl() {
|
||||
var (
|
||||
mchID string = "1629276485" // 商户号
|
||||
mchCertificateSerialNumber string = "3C7E21B74C04BE6227A690EB44184F219D763F92" // 商户证书序列号
|
||||
mchAPIv3Key string = "ChengDuBale0123456789qwertyuiopa" // 商户APIv3密钥
|
||||
)
|
||||
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
|
||||
//mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
|
||||
mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/Users/lsxd/code/php/yxxt/market/config/wechatcash/apiclient_key.pem")
|
||||
if err != nil {
|
||||
log.Printf("load merchant private key error:%s", err)
|
||||
return
|
||||
}
|
||||
ctx := context.Background()
|
||||
// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
|
||||
opts := []core.ClientOption{
|
||||
option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
|
||||
}
|
||||
client, err := core.NewClient(ctx, opts...)
|
||||
if err != nil {
|
||||
log.Printf("new wechat pay client err:%s", err)
|
||||
return
|
||||
}
|
||||
svc := transferbatch.TransferDetailApiService{Client: client}
|
||||
resp, result, err := svc.GetTransferDetailByNo(ctx,
|
||||
transferbatch.GetTransferDetailByNoRequest{
|
||||
BatchId: core.String("1030000071100999991182020050700019480001"),
|
||||
DetailId: core.String("1040000071100999991182020050700019500100"),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
// 处理错误
|
||||
log.Printf("call GetTransferDetailByNo err:%s", err)
|
||||
} else {
|
||||
// 处理返回结果
|
||||
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
|
||||
}
|
||||
}
|
||||
|
||||
func verify(ctx context.Context, c *weixin.Server) error {
|
||||
err := c.Verify(ctx, "", "")
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue