diff --git a/.gitignore b/.gitignore index c47138d9..9f78aa5c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ .DS_Store environment.yml -environment.yaml \ No newline at end of file +environment.yaml + +temp.go \ No newline at end of file diff --git a/go.mod b/go.mod index f6277e02..749d1423 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,17 @@ module github.com/ArtisanCloud/go-wechat go 1.16 +//replace github.com/ArtisanCloud/go-libs => ../go-libs +// +//replace github.com/ArtisanCloud/go-socialite => ../go-socialite + require ( - github.com/ArtisanCloud/go-libs v1.0.9 // indirect - github.com/ArtisanCloud/ubt-go v1.0.4 // indirect + github.com/ArtisanCloud/go-libs v1.0.11 + github.com/ArtisanCloud/go-socialite v1.0.0 + github.com/gin-gonic/gin v1.7.1 // indirect + github.com/go-redis/redis/v8 v8.10.0 // indirect + github.com/mattn/go-isatty v0.0.13 // indirect + golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect + golang.org/x/sys v0.0.0-20210608053332-aa57babbf139 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 4e4af732..6a83891d 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,16 @@ -github.com/ArtisanCloud/go-libs v1.0.9 h1:lF6lx8qZ7OIhvbVHt9SEJMBtn+jBfa7ZthMFL5Xwozc= -github.com/ArtisanCloud/go-libs v1.0.9/go.mod h1:NMCmLHB/v5cWOr62XMqIn0Q+N6m7UfGdx/bP++Y2kKM= -github.com/ArtisanCloud/ubt-go v1.0.4 h1:pEdYcP1+6SYzFkSyciRse8ORgWJGFg39thJjbvYLHEc= -github.com/ArtisanCloud/ubt-go v1.0.4/go.mod h1:eQJ8xHNbsYhMc1N353bDSCw2hHKPGfWV3UIwCMsg4uQ= +github.com/ArtisanCloud/go-libs v1.0.11 h1:CF39XsRaOKyphG7eoUVDkdqj2L2DUKfSrDr+tZyYbMI= +github.com/ArtisanCloud/go-libs v1.0.11/go.mod h1:QdDzmJskQvtLTwVpF6KZqnFEwBfTdIpF0FLy6WHvKmA= +github.com/ArtisanCloud/go-socialite v1.0.0 h1:eQnhkQTP8a7qr3QXFU1YOaf1jHJL6UnrmLNPowruUp8= +github.com/ArtisanCloud/go-socialite v1.0.0/go.mod h1:/VYnYt7mGKZxPyWr+qPlLv1/+H6xcZP+B7XdsbNhgt0= +github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= -github.com/elliotchance/phpserialize v1.3.0/go.mod h1:gt7XX9+ETUcLXbtTKEuyrqW3lcLUAeS/AnGZ2e49TZs= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= @@ -23,9 +26,10 @@ github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GO github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= github.com/go-redis/redis/v8 v8.8.0/go.mod h1:F7resOH5Kdug49Otu24RjHWwgK7u9AmtqWMnCV1iP5Y= +github.com/go-redis/redis/v8 v8.10.0 h1:OZwrQKuZqdJ4QIM8wn8rnuz868Li91xA3J2DEq+TPGA= +github.com/go-redis/redis/v8 v8.10.0/go.mod h1:vXLTvigok0VtUX0znvbcEW1SOt4OA9CU1ZfnOtKOaiM= github.com/golang-module/carbon v1.3.5/go.mod h1:wIIzB2BwewCNV4KyXfAASbAIsCJpwceR9JwVrgqdLIw= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= 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= @@ -33,41 +37,50 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU 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.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 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/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/guonaihong/gout v0.1.8 h1:upJrG4yB4HxKt2XIeIZ/JYK7WtGcwPXl+2xiFkP7VnU= -github.com/guonaihong/gout v0.1.8/go.mod h1:P6P8+0+toYgmhFqzLxVde+9vQbCDHrxn56V9TglC5io= +github.com/guonaihong/gout v0.1.11 h1:Sl4OwyNtp1BoMZXankNC0DimAPuh9kgBsZIGynD9kiw= +github.com/guonaihong/gout v0.1.11/go.mod h1:JkjNv1G2oRWvFgP/r4DUbYhoeIBB0zMP2j1ID+5CYpU= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= -github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA= +github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.15.0 h1:1V1NfVQR87RtWAgp1lv9JZJ5Jap+XFGKPi00andXGi4= github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/onsi/gomega v1.10.5 h1:7n6FEkpFmfCoo2t+YYqXH0evK+a9ICQz0xcAy9dYcaQ= github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48= +github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= +github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= @@ -75,24 +88,33 @@ github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.opentelemetry.io/otel v0.19.0/go.mod h1:j9bF567N9EfomkSidSfmMwIwIBuP37AMAIzVW85OxSg= +go.opentelemetry.io/otel v0.20.0 h1:eaP0Fqu7SXHwvjiqDq83zImeehOHX8doTvU9AwXON8g= +go.opentelemetry.io/otel v0.20.0/go.mod h1:Y3ugLH2oa81t5QO+Lty+zXf8zC9L26ax4Nzoxm/dooo= go.opentelemetry.io/otel/metric v0.19.0/go.mod h1:8f9fglJPRnXuskQmKpnad31lcLJ2VmNNqIsx/uIwBSc= +go.opentelemetry.io/otel/metric v0.20.0 h1:4kzhXFP+btKm4jwxpjIqjs41A7MakRFUS86bqLHTIw8= +go.opentelemetry.io/otel/metric v0.20.0/go.mod h1:598I5tYlH1vzBjn+BTuhzTCSb/9debfNp6R3s7Pr1eU= go.opentelemetry.io/otel/oteltest v0.19.0/go.mod h1:tI4yxwh8U21v7JD6R3BcA/2+RBoTKFexE/PJ/nSO7IA= +go.opentelemetry.io/otel/oteltest v0.20.0 h1:HiITxCawalo5vQzdHfKeZurV8x7ljcqAgiWzF6Vaeaw= +go.opentelemetry.io/otel/oteltest v0.20.0/go.mod h1:L7bgKf9ZB7qCwT9Up7i9/pn0PWIa9FqQ2IQ8LoxiGnw= go.opentelemetry.io/otel/trace v0.19.0/go.mod h1:4IXiNextNOpPnRlI4ryK69mn5iC84bjBWZQA5DXz/qg= +go.opentelemetry.io/otel/trace v0.20.0 h1:1DL6EXUdcg95gukhuRRvLDO/4X5THh/5dIV52lqtnbw= +go.opentelemetry.io/otel/trace v0.20.0/go.mod h1:6GjCW8zgDjwGHGa6GkyeB8+/5vjT16gUEi0Nf1iBdgw= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b h1:wSOdpTq0/eI46Ez/LkDwIsAKA71YP2SRKBODiRWM0as= golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210525063256-abc453219eb5 h1:wjuX4b5yYQnEQHzd+CBcrcC6OVR2J1CN6mUy0oSxIPo= +golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -102,22 +124,27 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210608053332-aa57babbf139 h1:C+AwYEtBp/VQwoLntUmQ/yx3MS9vmZaKNdw5eOpoQe8= +golang.org/x/sys v0.0.0-20210608053332-aa57babbf139/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 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= @@ -125,13 +152,19 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ 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.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/gorm v1.21.6/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0= diff --git a/main.go b/main.go index cd3a06fa..523c4475 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,33 @@ package main -import "fmt" +import ( + "fmt" + fmt2 "github.com/ArtisanCloud/go-libs/fmt" + "github.com/ArtisanCloud/go-wechat/src/work" +) func main() { - fmt.Printf("hello Wechat!") + fmt.Printf("hello Wechat! \n") -} \ No newline at end of file + config := GetConfig() + + app := work.NewWork(config) + //fmt2.Dump(app) + fmt2.Dump(app.GetConfig()) + + //token := app.AccessToken.GetToken() + //fmt2.Dump(token) + + //cType := reflect.TypeOf((*app.Components)["base"].(*base.Client)) + //fmt.Printf("kind %s \n", cType.Kind()) + //fmt.Printf("type %v \n", cType) + + //ips := app.Base.GetCallbackIp() + //fmt2.Dump(ips) + //domainIps := app.Base.GetAPIDomainIP() + //fmt2.Dump(domainIps) + + + +} diff --git a/src/kernel/accessToken.go b/src/kernel/accessToken.go new file mode 100644 index 00000000..aa4ae8e8 --- /dev/null +++ b/src/kernel/accessToken.go @@ -0,0 +1,212 @@ +package kernel + +import ( + "crypto/md5" + "encoding/json" + "fmt" + "github.com/ArtisanCloud/go-libs/exception" + http2 "github.com/ArtisanCloud/go-libs/http" + httpContract "github.com/ArtisanCloud/go-libs/http/contract" + "github.com/ArtisanCloud/go-libs/object" + "github.com/ArtisanCloud/go-wechat/src/kernel/contract" + response2 "github.com/ArtisanCloud/go-wechat/src/kernel/response" + "net/http" + "time" +) + +type AccessToken struct { + App *ApplicationInterface + + *http2.HttpRequest + *http2.HttpResponse + + RequestMethod string + EndpointToGetToken string + QueryName string + Token object.HashMap + TokenKey string + CachePrefix string + + *CacheToken + + GetCredentials func() *object.StringMap +} + +func NewAccessToken(app *ApplicationInterface) *AccessToken { + config := (*app).GetContainer().GetConfig() + + token := &AccessToken{ + App: app, + HttpRequest: http2.NewHttpRequest(config), + + RequestMethod: "GET", + EndpointToGetToken: "", + QueryName: "", + Token: nil, + TokenKey: "access_token", + CachePrefix: "ac.go.wechat.kernel.access_token.", + + CacheToken: &CacheToken{}, + } + + return token +} + +func (accessToken *AccessToken) GetRefreshedToken() *response2.ResponseGetToken { + return accessToken.GetToken(true) +} + +func (accessToken *AccessToken) GetToken(refresh bool) (resToken *response2.ResponseGetToken) { + cacheKey := accessToken.getCacheKey() + cache := accessToken.getCache() + + // get token from cache + if !refresh && cache.Has(cacheKey) { + value, err := cache.Get(cacheKey, nil) + if err == nil { + token := value.(*object.HashMap) + return &response2.ResponseGetToken{ + AccessToken: (*token)[accessToken.TokenKey].(string), + ExpiresIn: (*token)["expires_in"].(int), + } + } + } + + // request token from wx + response := accessToken.requestToken(accessToken.GetCredentials()) + + //// save token into cache + resToken = response.(*response2.ResponseGetToken) + var expireIn int = 7200 + if resToken.ExpiresIn > 0 { + expireIn = resToken.ExpiresIn + } + accessToken.SetToken(resToken.AccessToken, expireIn) + + // tbd dispatch a event for AccessTokenRefresh + + return resToken +} + +func (accessToken *AccessToken) SetToken(token string, lifeTime int) (tokenInterface contract.AccessTokenInterface, err error) { + if lifeTime <= 0 { + lifeTime = 7200 + } + + // set token into cache + cache := accessToken.getCache() + err = cache.Set(accessToken.getCacheKey(), &object.HashMap{ + accessToken.TokenKey: token, + "expires_in": lifeTime, + }, time.Duration(lifeTime)*time.Second) + + defer (&exception.Exception{}).HandleException(nil, "accessToken.set.token", nil) + if !cache.Has(accessToken.getCacheKey()) { + panic("Failed to cache access token.") + return nil, err + } + return accessToken, err + +} + +func (accessToken *AccessToken) Refresh() contract.AccessTokenInterface { + + return nil +} + +func (accessToken *AccessToken) requestToken(credentials *object.StringMap) httpContract.ResponseContract { + + // tbf + return &response2.ResponseGetToken{ + AccessToken: "FwhFYGuWs47wxxUQHf5gbOIwMBe8ohu3EUnhF-x6uw4VX55-m46bnQUHLJ1nM5R0WAVfrLHvdn6XJtkMkzRkN_E75edrNzWK6IZxx3RwUJNowZEg3dcU3NEygFGfzUEGLS5fiB4GtNPOi-HKUhQumAMcP0lncEij2Hjg95FTqS4YBRNVG4OL92h8RAiP-yllfDvt2URk6tntGe4HaxAGdA", + ExpiresIn: 7200, + ResponseWX: &response2.ResponseWX{ + ErrCode: 0, + ErrMSG: "ok", + }, + } + + res := accessToken.sendRequest(credentials) + token := res.(*response2.ResponseGetToken) + defer (&exception.Exception{}).HandleException(nil, "accessToken.request.token", nil) + if token == nil || token.AccessToken == "" { + panic(fmt.Sprintf("Request access_token fail: %v", res)) + return nil + } + + return token +} + +func (accessToken *AccessToken) ApplyToRequest(request *http.Request, requestOptions *object.HashMap) *http.Request { + + // query Access Token map + mapToken := accessToken.getQuery() + q := request.URL.Query() + for key, value := range *mapToken { + q.Set(key, value) + } + request.URL.RawQuery = q.Encode() + + return request +} + +func (accessToken *AccessToken) sendRequest(credential *object.StringMap) httpContract.ResponseContract { + + key := "json" + if accessToken.RequestMethod == "GET" { + key = "query" + } + options := &object.HashMap{ + key: credential, + } + + res := &response2.ResponseGetToken{} + + accessToken.SetHttpClient(accessToken.GetHttpClient()).PerformRequest( + accessToken.getEndpoint(), + accessToken.RequestMethod, + options, + res, + ) + return res +} + +func (accessToken *AccessToken) getCacheKey() string { + data, _ := json.Marshal(accessToken.GetCredentials()) + buffer := md5.Sum(data) + + return accessToken.CachePrefix + string(buffer[:]) +} + +func (accessToken *AccessToken) getQuery() *object.StringMap { + // set the current token key + var key string + if accessToken.QueryName != "" { + key = accessToken.QueryName + } else { + key = accessToken.TokenKey + } + + // get token string map + resToken := accessToken.GetToken(false) + arrayReturn := &object.StringMap{ + key: resToken.AccessToken, + } + + return arrayReturn + +} + +func (accessToken *AccessToken) getEndpoint() string { + defer (&exception.Exception{}).HandleException(nil, "accessToken.get.endpoint", accessToken) + if accessToken.EndpointToGetToken == "" { + panic("No endpoint for access token request.") + return "" + } + + return accessToken.EndpointToGetToken +} + +func (accessToken *AccessToken) getTokenKey() string { + return accessToken.TokenKey +} diff --git a/src/kernel/baseClient.go b/src/kernel/baseClient.go new file mode 100644 index 00000000..87f8f411 --- /dev/null +++ b/src/kernel/baseClient.go @@ -0,0 +1,146 @@ +package kernel + +import ( + "fmt" + "github.com/ArtisanCloud/go-libs/http" + "github.com/ArtisanCloud/go-libs/object" + http2 "net/http" +) + +type BaseClient struct { + *http.HttpRequest + *http.HttpResponse + + App *ApplicationInterface + Token *AccessToken +} + +func NewBaseClient(app *ApplicationInterface, token *AccessToken) *BaseClient { + config := (*app).GetContainer().GetConfig() + + if token == nil { + token = (*app).GetAccessToken() + } + + client := &BaseClient{ + HttpRequest: http.NewHttpRequest(config), + App: app, + Token: token, + } + return client + +} + +func (client *BaseClient) HttpGet(url string, query object.StringMap, outResponse interface{}) interface{} { + return client.Request( + url, + "GET", + &object.HashMap{ + "query": query, + }, + false, + outResponse, + ) +} + +func (client *BaseClient) HttpPost(url string, data object.HashMap, outResponse interface{}) interface{} { + return client.Request( + url, + "POST", + &object.HashMap{ + "form_params": data, + }, + false, + outResponse, + ) +} + +func (client *BaseClient) HttpPostJson(url string, data object.HashMap, query object.StringMap, outResponse interface{}) interface{} { + return client.Request( + url, + "POST", + &object.HashMap{ + "query": query, + "form_params": data, + }, + false, + outResponse, + ) +} + +func (client *BaseClient) Request(url string, method string, options *object.HashMap, returnRaw bool, outResponse interface{}) interface{} { + + // to be setup middleware here + if client.Middlewares == nil { + client.registerHttpMiddlewares() + } + // http client request + response := client.PerformRequest(url, method, options, outResponse) + + if returnRaw { + return response + } else { + config := *(*client.App).GetContainer().Config + client.CastResponseToType(response, config["response_type"]) + } + return response +} + +func (client *BaseClient) registerHttpMiddlewares() { + + client.Middlewares = []interface{}{} + + // retry + //client.PushMiddleware(client.retryMiddleware(), "retry") + // access token + client.PushMiddleware(client.accessTokenMiddleware(), "access_token") + // log + //client.PushMiddleware(client.logMiddleware(), "log") + +} + +// ---------------------------------------------------------------------- +type MiddlewareAccessToken struct { + *BaseClient +} +type MiddlewareLogMiddleware struct { + *BaseClient +} +type MiddlewareRetry struct { + *BaseClient +} + +func (d *MiddlewareAccessToken) ModifyRequest(req *http2.Request) error { + accessToken := (*d.App).GetAccessToken() + + if accessToken != nil { + config := (*d.App).GetContainer().Config + accessToken.ApplyToRequest(req, config) + } + + return nil +} +func (d *MiddlewareLogMiddleware) ModifyRequest(req *http2.Request) error { + fmt.Println("logMiddleware") + return nil +} +func (d *MiddlewareRetry) ModifyRequest(req *http2.Request) error { + fmt.Println("retryMiddleware") + return nil +} + +func (client *BaseClient) accessTokenMiddleware() interface{} { + return &MiddlewareAccessToken{ + client, + } +} +func (client *BaseClient) logMiddleware() interface{} { + return &MiddlewareLogMiddleware{ + client, + } +} +func (client *BaseClient) retryMiddleware() interface{} { + return &MiddlewareRetry{ + client, + } +} diff --git a/src/kernel/cacheToken.go b/src/kernel/cacheToken.go new file mode 100644 index 00000000..7953a8ca --- /dev/null +++ b/src/kernel/cacheToken.go @@ -0,0 +1,37 @@ +package kernel + +import ( + "github.com/ArtisanCloud/go-libs/cache" + "time" +) + +type CacheToken struct { + Cache cache.CacheInterface +} + +func (cacheToken *CacheToken) getCache() cache.CacheInterface { + if cacheToken.Cache != nil { + return cacheToken.Cache + } + + // tbd global redis exist + + // create default cache + cacheToken.Cache = cacheToken.createDefaultCache() + + return cacheToken.Cache +} + +func (cacheToken *CacheToken) setCache(cache cache.CacheInterface) *CacheToken { + + cacheToken.Cache = cache + + return cacheToken +} + +func (cacheToken *CacheToken) createDefaultCache() cache.CacheInterface { + + cacheToken.Cache = cache.NewMemCache("ac.go.wx", time.Duration(1500), "") + + return cacheToken.Cache +} diff --git a/src/kernel/config.go b/src/kernel/config.go new file mode 100644 index 00000000..9cc7a562 --- /dev/null +++ b/src/kernel/config.go @@ -0,0 +1,13 @@ +package kernel + +import "github.com/ArtisanCloud/go-libs/object" + +type Config struct { + *object.Collection +} + +func NewConfig(items *object.HashMap) *Config{ + return &Config{ + object.NewCollection(items), + } +} \ No newline at end of file diff --git a/src/kernel/contract/accessTokenInterface.go b/src/kernel/contract/accessTokenInterface.go new file mode 100644 index 00000000..e294702b --- /dev/null +++ b/src/kernel/contract/accessTokenInterface.go @@ -0,0 +1,15 @@ +package contract + +import ( + "github.com/ArtisanCloud/go-libs/object" + response2 "github.com/ArtisanCloud/go-wechat/src/kernel/response" + "net/http" +) + +type ( + AccessTokenInterface interface { + GetToken(refresh bool) (resToken *response2.ResponseGetToken) + Refresh() AccessTokenInterface + ApplyToRequest(request *http.Request, requestOptions *object.HashMap) *http.Request + } +) diff --git a/src/kernel/exception/exception.go b/src/kernel/exception/exception.go new file mode 100644 index 00000000..c5710647 --- /dev/null +++ b/src/kernel/exception/exception.go @@ -0,0 +1,8 @@ +package exception + +import "github.com/ArtisanCloud/go-libs/exception" + +type Exception struct { + exception.Exception +} + diff --git a/src/kernel/providers/configProvider.go b/src/kernel/providers/configProvider.go new file mode 100644 index 00000000..0797d5e9 --- /dev/null +++ b/src/kernel/providers/configProvider.go @@ -0,0 +1,8 @@ +package providers + +import "github.com/ArtisanCloud/go-wechat/src/kernel" + +func RegisterProvider(app kernel.ApplicationInterface) *kernel.Config { + + return kernel.NewConfig(app.GetContainer().GetConfig()) +} diff --git a/src/kernel/response/getToken.go b/src/kernel/response/getToken.go new file mode 100644 index 00000000..f331b1a2 --- /dev/null +++ b/src/kernel/response/getToken.go @@ -0,0 +1,7 @@ +package response + +type ResponseGetToken struct { + AccessToken string `json:"access_token"` + ExpiresIn int `json:"expires_in"` + *ResponseWX +} diff --git a/src/kernel/response/wx.go b/src/kernel/response/wx.go new file mode 100644 index 00000000..3b98ab09 --- /dev/null +++ b/src/kernel/response/wx.go @@ -0,0 +1,19 @@ +package response + +import "github.com/ArtisanCloud/go-libs/object" + +type ResponseWX struct { + ErrCode int `json:"errcode"` + ErrMSG string `json:"errmsg"` +} + +func (res *ResponseWX)GetBody() *object.HashMap{ + return nil +} +func (res *ResponseWX)GetHeaders() *object.HashMap{ + return nil +} + +func (res *ResponseWX)GetStatusCode() int{ + return 200 +} \ No newline at end of file diff --git a/src/kernel/serviceContainer.go b/src/kernel/serviceContainer.go new file mode 100644 index 00000000..d9b1c78c --- /dev/null +++ b/src/kernel/serviceContainer.go @@ -0,0 +1,44 @@ +package kernel + +import ( + "github.com/ArtisanCloud/go-libs/object" +) + +type ApplicationInterface interface { + GetContainer() *ServiceContainer + GetAccessToken() *AccessToken +} + +type ServiceContainer struct { + ID int + + DefaultConfig *object.HashMap + UserConfig *object.HashMap + Config *object.HashMap +} + +func (container *ServiceContainer) getBaseConfig() *object.HashMap { + return &object.HashMap{ + // http://docs.guzzlephp.org/en/stable/request-options.html + "http": object.HashMap{ + "timeout": 30.0, + "base_uri": "https://api.weixin.qq.com/", + }, + } +} + +func (container *ServiceContainer) GetConfig() *object.HashMap { + + // init container config + var config *object.HashMap + if container.Config != nil { + config = container.Config + } else { + config = container.getBaseConfig() + } + + // merge config + container.Config = object.MergeHashMap(config, container.DefaultConfig, container.UserConfig) + + return container.Config +} diff --git a/src/miniProgram/application.go b/src/miniProgram/application.go new file mode 100644 index 00000000..036510ab --- /dev/null +++ b/src/miniProgram/application.go @@ -0,0 +1,12 @@ +package miniProgram + +type MiniProgram struct { + Name string +} + +func (app *MiniProgram)PrintName() { + println("MiniProgram") +} + + + diff --git a/src/work/application.go b/src/work/application.go new file mode 100644 index 00000000..30321590 --- /dev/null +++ b/src/work/application.go @@ -0,0 +1,56 @@ +package work + +import ( + "github.com/ArtisanCloud/go-libs/object" + "github.com/ArtisanCloud/go-wechat/src/kernel" + "github.com/ArtisanCloud/go-wechat/src/kernel/providers" + "github.com/ArtisanCloud/go-wechat/src/work/auth" + "github.com/ArtisanCloud/go-wechat/src/work/base" + "github.com/ArtisanCloud/go-wechat/src/work/oauth" +) + +type Work struct { + *kernel.ServiceContainer + + Base *base.Client + AccessToken *auth.AccessToken + OAuth *oauth.Manager + Config *kernel.Config +} + +func NewWork(config *object.HashMap) *Work { + // init an app container + container := &kernel.ServiceContainer{ + UserConfig: config, + DefaultConfig: &object.HashMap{ + "http": map[string]string{ + "base_uri": "https://qyapi.weixin.qq.com/", + }, + }, + } + + // init app + app := &Work{ + ServiceContainer: container, + } + + // register Auth + app.AccessToken = auth.RegisterProvider(app) + // register Base + app.Base = base.RegisterProvider(app) + + // register oauth + app.OAuth = oauth.RegisterProvider(app) + + app.Config = providers.RegisterProvider(app) + + return app +} + +func (app *Work) GetContainer() *kernel.ServiceContainer { + return app.ServiceContainer +} + +func (app *Work) GetAccessToken() *kernel.AccessToken { + return app.AccessToken.AccessToken +} diff --git a/src/work/auth/accessToken.go b/src/work/auth/accessToken.go new file mode 100644 index 00000000..347b55ad --- /dev/null +++ b/src/work/auth/accessToken.go @@ -0,0 +1,36 @@ +package auth + +// #reference: https://open.work.weixin.qq.com/api/doc/90000/90135/91039 + +import ( + "github.com/ArtisanCloud/go-libs/object" + "github.com/ArtisanCloud/go-wechat/src/kernel" +) + +type AccessToken struct { + *kernel.AccessToken +} + +func NewAccessToken(app *kernel.ApplicationInterface) *AccessToken { + token := &AccessToken{ + kernel.NewAccessToken(app), + } + + // Override fields and functions + token.EndpointToGetToken = "cgi-bin/gettoken" + token.OverrideGetCredentials() + + return token +} + + +// Override GetCredentials +func (accessToken *AccessToken) OverrideGetCredentials() { + config := (*accessToken.App).GetContainer().GetConfig() + accessToken.GetCredentials = func() *object.StringMap { + return &object.StringMap{ + "corpid": (*config)["corp_id"].(string), + "corpsecret": (*config)["secret"].(string), + } + } +} diff --git a/src/work/auth/provider.go b/src/work/auth/provider.go new file mode 100644 index 00000000..0bc8a68e --- /dev/null +++ b/src/work/auth/provider.go @@ -0,0 +1,11 @@ +package auth + +import ( + "github.com/ArtisanCloud/go-wechat/src/kernel" +) + +func RegisterProvider(app kernel.ApplicationInterface) *AccessToken { + + return NewAccessToken(&app) + +} diff --git a/src/work/base/client.go b/src/work/base/client.go new file mode 100644 index 00000000..4799ceca --- /dev/null +++ b/src/work/base/client.go @@ -0,0 +1,30 @@ +package base + +import ( + "github.com/ArtisanCloud/go-wechat/src/kernel" + "github.com/ArtisanCloud/go-wechat/src/work/base/response" +) + +type Client struct { + *kernel.BaseClient +} + +func (comp *Client) GetCallbackIp() *response.ResponseGetCallBackIp { + + result := &response.ResponseGetCallBackIp{} + + comp.HttpGet("cgi-bin/getcallbackip", nil, result) + + return result +} + + +func (comp *Client) GetAPIDomainIP() *response.ResponseGetAPIDomainIP { + + result := &response.ResponseGetAPIDomainIP{} + + comp.HttpGet("cgi-bin/get_api_domain_ip", nil, result) + + return result +} + diff --git a/src/work/base/provider.go b/src/work/base/provider.go new file mode 100644 index 00000000..8bd5a714 --- /dev/null +++ b/src/work/base/provider.go @@ -0,0 +1,13 @@ +package base + +import ( + "github.com/ArtisanCloud/go-wechat/src/kernel" +) + +func RegisterProvider(app kernel.ApplicationInterface) *Client { + + return &Client{ + kernel.NewBaseClient(&app, nil), + } + +} diff --git a/src/work/base/response/responseGetAPIDomainIP.go b/src/work/base/response/responseGetAPIDomainIP.go new file mode 100644 index 00000000..50d987ee --- /dev/null +++ b/src/work/base/response/responseGetAPIDomainIP.go @@ -0,0 +1,11 @@ +package response + +import ( + "github.com/ArtisanCloud/go-wechat/src/kernel/response" +) + +type ResponseGetAPIDomainIP struct { + IPList []string `json:"ip_list"` + *response.ResponseWX +} + diff --git a/src/work/base/response/responseGetCallbackIp.go b/src/work/base/response/responseGetCallbackIp.go new file mode 100644 index 00000000..63ac44a5 --- /dev/null +++ b/src/work/base/response/responseGetCallbackIp.go @@ -0,0 +1,11 @@ +package response + +import ( + "github.com/ArtisanCloud/go-wechat/src/kernel/response" +) + +type ResponseGetCallBackIp struct { + IPList []string `json:"ip_list"` + *response.ResponseWX +} + diff --git a/src/work/oauth/manager.go b/src/work/oauth/manager.go new file mode 100644 index 00000000..5894af55 --- /dev/null +++ b/src/work/oauth/manager.go @@ -0,0 +1,24 @@ +package oauth + +import ( + "github.com/ArtisanCloud/go-libs/object" + "github.com/ArtisanCloud/go-socialite/src/providers" + "github.com/ArtisanCloud/go-wechat/src/kernel" +) + +type Manager struct { + Config *object.HashMap + App *kernel.ApplicationInterface + Provider *providers.WeCom +} + +func NewManager(config *object.HashMap,app *kernel.ApplicationInterface) *Manager { + + manager:= &Manager{ + config, + app, + nil, + } + return manager + +} \ No newline at end of file diff --git a/src/work/oauth/provider.go b/src/work/oauth/provider.go new file mode 100644 index 00000000..c89094a4 --- /dev/null +++ b/src/work/oauth/provider.go @@ -0,0 +1,51 @@ +package oauth + +import ( + "fmt" + "github.com/ArtisanCloud/go-libs/object" + "github.com/ArtisanCloud/go-wechat/src/kernel" + "github.com/ArtisanCloud/go-wechat/src/kernel/exception" + "strings" +) + +func RegisterProvider(app kernel.ApplicationInterface) *Manager { + + config := *app.GetContainer().Config + + manager := NewManager(&object.HashMap{ + "wecom": &object.HashMap{ + "client_id": config["corp_id"].(string), + "client_secret": "", + "corp_id": config["corp_id"].(string), + "corp_secret": config["secret"].(string), + //"redirect": prepareCallbackUrl(app), + }, + }, &app) + + + + //scopes := manager.Config + + + //if len(scopes)>0{ + // + //} + + return manager + +} + +func prepareCallbackUrl(app kernel.ApplicationInterface) string { + config := *app.GetContainer().Config + + callback := config["oauth.callback"].(string) + if strings.Index(callback, "http") == 0 { + return callback + } else { + // have to setup a complete url with host + defer (&exception.Exception{}).HandleException(nil, "oauth.prepare.callback.url", nil) + panic(fmt.Sprintf("OAuth callback format invalid, please make sure that schema 'http' added: %v", callback)) + + } + +}