├── cmd └── data │ └── .gitignore ├── .gitignore ├── doc └── img │ └── sdk.jpg ├── go.mod ├── .github ├── workflows │ └── ci.yaml └── FUNDING.yml ├── LICENSE ├── go.sum ├── apis ├── refund │ ├── example_refund_test.go │ ├── example_refund_query_test.go │ ├── refund_query.go │ ├── refund.go │ ├── refund_test.go │ └── refund_query_test.go ├── dev_util │ ├── example_report_test.go │ ├── example_get_sign_key_test.go │ ├── get_sign_key.go │ ├── report.go │ ├── report_test.go │ └── get_sign_key_test.go ├── native │ ├── example_short_url_test.go │ ├── short_url.go │ └── short_url_test.go ├── order │ ├── example_close_order_test.go │ ├── example_order_query_test.go │ ├── example_unified_order_test.go │ ├── unified_order.go │ ├── close_order.go │ ├── order_query.go │ ├── close_order_test.go │ ├── order_query_test.go │ └── unified_order_test.go ├── corp_pay │ ├── example_pay_bank_test.go │ ├── example_query_bank_test.go │ ├── example_transfers_test.go │ ├── example_get_public_key_test.go │ ├── example_get_transfer_info_test.go │ ├── get_public_key.go │ ├── transfers.go │ ├── query_bank.go │ ├── pay_bank.go │ ├── get_transfer_info.go │ ├── pay_bank_test.go │ ├── query_bank_test.go │ ├── get_public_key_test.go │ ├── transfers_test.go │ └── get_transfer_info_test.go ├── coupon │ ├── example_send_coupon_test.go │ ├── example_query_coupon_stock_test.go │ ├── example_query_coupons_info_test.go │ ├── query_coupons_info.go │ ├── query_coupon_stock.go │ ├── send_coupon.go │ ├── send_coupon_test.go │ ├── query_coupons_info_test.go │ └── query_coupon_stock_test.go ├── micropay │ ├── example_reverse_test.go │ ├── example_micro_pay_test.go │ ├── example_auth_code_to_open_id_test.go │ ├── auth_code_to_open_id.go │ ├── reverse.go │ ├── micro_pay.go │ ├── micro_pay_test.go │ ├── reverse_test.go │ └── auth_code_to_open_id_test.go ├── download │ ├── example_download_bill_test.go │ ├── example_batch_query_comment_test.go │ ├── example_download_fund_flow_test.go │ ├── batch_query_comment.go │ ├── download_fund_flow.go │ ├── download_bill.go │ ├── download_bill_test.go │ ├── download_fund_flow_test.go │ └── batch_query_comment_test.go ├── lucky_money │ ├── example_get_hb_info_test.go │ ├── example_send_red_pack_test.go │ ├── example_send_group_red_pack_test.go │ ├── example_send_miniprogram_hb_test.go │ ├── get_hb_info.go │ ├── send_miniprogram_hb.go │ ├── send_group_red_pack.go │ ├── send_red_pack.go │ ├── get_hb_info_test.go │ ├── send_red_pack_test.go │ ├── send_group_red_pack_test.go │ └── send_miniprogram_hb_test.go └── profit_sharing │ ├── example_profit_sharing_test.go │ ├── example_multi_profit_sharing_test.go │ ├── example_profit_sharing_finish_test.go │ ├── example_profit_sharing_query_test.go │ ├── example_profit_sharing_return_test.go │ ├── example_profit_sharing_add_receiver_test.go │ ├── example_profit_sharing_return_query_test.go │ ├── example_profit_sharing_remove_receiver_test.go │ ├── profit_sharing_query.go │ ├── profit_sharing.go │ ├── profit_sharing_add_receiver.go │ ├── profit_sharing_remove_receiver.go │ ├── profit_sharing_return_query.go │ ├── profit_sharing_finish.go │ ├── multi_profit_sharing.go │ ├── profit_sharing_return.go │ ├── profit_sharing_test.go │ ├── profit_sharing_query_test.go │ ├── multi_profit_sharing_test.go │ ├── profit_sharing_finish_test.go │ ├── profit_sharing_return_test.go │ ├── profit_sharing_add_receiver_test.go │ ├── profit_sharing_return_query_test.go │ └── profit_sharing_remove_receiver_test.go ├── util ├── randstring.go ├── util.go ├── randstring_test.go ├── util_test.go ├── aes_crypto.go ├── string_map_xml.go ├── ecb.go └── string_map_xml_test.go ├── test └── test.go ├── types └── types.go ├── README.md ├── wxpay_test.go ├── wxpay.go ├── server.go ├── client.go └── server_test.go /cmd/data/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea/ 3 | demo/ 4 | *tmp.go 5 | TODO 6 | -------------------------------------------------------------------------------- /doc/img/sdk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fastwego/wxpay/HEAD/doc/img/sdk.jpg -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/fastwego/wxpay 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/iancoleman/strcase v0.1.2 7 | golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9 8 | ) 9 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | on: push 2 | name: golang-ci 3 | jobs: 4 | checks: 5 | name: run-test 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@main 9 | 10 | - name: Use Go 1.15 11 | uses: cedrickring/golang-action@1.6.0 12 | env: 13 | GO111MODULE: "on" 14 | 15 | - name: Use Go 1.14 16 | uses: cedrickring/golang-action/go1.14@1.6.0 17 | env: 18 | GO111MODULE: "on" 19 | 20 | - name: Use Go 1.13 21 | uses: cedrickring/golang-action/go1.13@1.6.0 22 | env: 23 | GO111MODULE: "on" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: ['https://public.zsxq.com/groups/48415121824218.html', 'https://pic2.zhimg.com/80/v2-6b84f07b309b6e1ad1b3141c3e9d34dc_1440w.png'] 13 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/iancoleman/strcase v0.1.2 h1:gnomlvw9tnV3ITTAxzKSgTF+8kFWcU/f+TgttpXGz1U= 2 | github.com/iancoleman/strcase v0.1.2/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= 3 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 4 | golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9 h1:umElSU9WZirRdgu2yFHY0ayQkEnKiOC1TtM3fWXFnoU= 5 | golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 6 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 7 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 8 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 9 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 10 | -------------------------------------------------------------------------------- /apis/refund/example_refund_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package refund_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/refund" 22 | ) 23 | 24 | func ExampleRefund() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := refund.Refund(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/dev_util/example_report_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package dev_util_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/dev_util" 22 | ) 23 | 24 | func ExampleReport() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := dev_util.Report(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/native/example_short_url_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package native_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/native" 22 | ) 23 | 24 | func ExampleShortUrl() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := native.ShortUrl(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/order/example_close_order_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package order_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/order" 22 | ) 23 | 24 | func ExampleCloseOrder() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := order.CloseOrder(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/order/example_order_query_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package order_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/order" 22 | ) 23 | 24 | func ExampleOrderQuery() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := order.OrderQuery(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/corp_pay/example_pay_bank_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package corp_pay_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/corp_pay" 22 | ) 23 | 24 | func ExamplePayBank() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := corp_pay.PayBank(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/coupon/example_send_coupon_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package coupon_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/coupon" 22 | ) 23 | 24 | func ExampleSendCoupon() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := coupon.SendCoupon(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/micropay/example_reverse_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package micropay_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/micropay" 22 | ) 23 | 24 | func ExampleReverse() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := micropay.Reverse(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/corp_pay/example_query_bank_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package corp_pay_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/corp_pay" 22 | ) 23 | 24 | func ExampleQueryBank() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := corp_pay.QueryBank(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/corp_pay/example_transfers_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package corp_pay_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/corp_pay" 22 | ) 23 | 24 | func ExampleTransfers() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := corp_pay.Transfers(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/micropay/example_micro_pay_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package micropay_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/micropay" 22 | ) 23 | 24 | func ExampleMicroPay() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := micropay.MicroPay(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/order/example_unified_order_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package order_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/order" 22 | ) 23 | 24 | func ExampleUnifiedOrder() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := order.UnifiedOrder(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/refund/example_refund_query_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package refund_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/refund" 22 | ) 23 | 24 | func ExampleRefundQuery() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := refund.RefundQuery(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/dev_util/example_get_sign_key_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package dev_util_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/dev_util" 22 | ) 23 | 24 | func ExampleGetSignKey() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := dev_util.GetSignKey(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/corp_pay/example_get_public_key_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package corp_pay_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/corp_pay" 22 | ) 23 | 24 | func ExampleGetPublicKey() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := corp_pay.GetPublicKey(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/download/example_download_bill_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package download_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/download" 22 | ) 23 | 24 | func ExampleDownloadBill() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := download.DownloadBill(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/coupon/example_query_coupon_stock_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package coupon_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/coupon" 22 | ) 23 | 24 | func ExampleQueryCouponStock() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := coupon.QueryCouponStock(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/coupon/example_query_coupons_info_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package coupon_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/coupon" 22 | ) 23 | 24 | func ExampleQueryCouponsInfo() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := coupon.QueryCouponsInfo(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/lucky_money/example_get_hb_info_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package lucky_money_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/lucky_money" 22 | ) 23 | 24 | func ExampleGetHBInfo() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := lucky_money.GetHBInfo(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/corp_pay/example_get_transfer_info_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package corp_pay_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/corp_pay" 22 | ) 23 | 24 | func ExampleGetTransferInfo() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := corp_pay.GetTransferInfo(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/lucky_money/example_send_red_pack_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package lucky_money_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/lucky_money" 22 | ) 23 | 24 | func ExampleSendRedPack() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := lucky_money.SendRedPack(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/download/example_batch_query_comment_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package download_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/download" 22 | ) 23 | 24 | func ExampleBatchQueryComment() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := download.BatchQueryComment(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/download/example_download_fund_flow_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package download_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/download" 22 | ) 23 | 24 | func ExampleDownloadFundFlow() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := download.DownloadFundFlow(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/micropay/example_auth_code_to_open_id_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package micropay_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/micropay" 22 | ) 23 | 24 | func ExampleAuthCodeToOpenId() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := micropay.AuthCodeToOpenId(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/lucky_money/example_send_group_red_pack_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package lucky_money_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/lucky_money" 22 | ) 23 | 24 | func ExampleSendGroupRedPack() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := lucky_money.SendGroupRedPack(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/profit_sharing/example_profit_sharing_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package profit_sharing_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/profit_sharing" 22 | ) 23 | 24 | func ExampleProfitSharing() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := profit_sharing.ProfitSharing(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/lucky_money/example_send_miniprogram_hb_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package lucky_money_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/lucky_money" 22 | ) 23 | 24 | func ExampleSendMiniprogramHB() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := lucky_money.SendMiniprogramHB(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/profit_sharing/example_multi_profit_sharing_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package profit_sharing_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/profit_sharing" 22 | ) 23 | 24 | func ExampleMultiProfitSharing() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := profit_sharing.MultiProfitSharing(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/profit_sharing/example_profit_sharing_finish_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package profit_sharing_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/profit_sharing" 22 | ) 23 | 24 | func ExampleProfitSharingFinish() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := profit_sharing.ProfitSharingFinish(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/profit_sharing/example_profit_sharing_query_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package profit_sharing_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/profit_sharing" 22 | ) 23 | 24 | func ExampleProfitSharingQuery() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := profit_sharing.ProfitSharingQuery(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/profit_sharing/example_profit_sharing_return_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package profit_sharing_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/profit_sharing" 22 | ) 23 | 24 | func ExampleProfitSharingReturn() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := profit_sharing.ProfitSharingReturn(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/profit_sharing/example_profit_sharing_add_receiver_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package profit_sharing_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/profit_sharing" 22 | ) 23 | 24 | func ExampleProfitSharingAddReceiver() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := profit_sharing.ProfitSharingAddReceiver(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/profit_sharing/example_profit_sharing_return_query_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package profit_sharing_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/profit_sharing" 22 | ) 23 | 24 | func ExampleProfitSharingReturnQuery() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := profit_sharing.ProfitSharingReturnQuery(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/profit_sharing/example_profit_sharing_remove_receiver_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package profit_sharing_test 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/fastwego/wxpay" 21 | "github.com/fastwego/wxpay/apis/profit_sharing" 22 | ) 23 | 24 | func ExampleProfitSharingRemoveReceiver() { 25 | var ctx *wxpay.WXPay 26 | 27 | params := map[string]string{ 28 | "appid": "APPID", 29 | // ... 30 | } 31 | resp, err := profit_sharing.ProfitSharingRemoveReceiver(ctx, params) 32 | 33 | fmt.Println(resp, err) 34 | } 35 | -------------------------------------------------------------------------------- /apis/download/batch_query_comment.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package download 下载 相关 16 | package download 17 | 18 | import "github.com/fastwego/wxpay" 19 | 20 | /* 21 | 拉取订单评价数据 22 | 23 | 商户可以通过该接口拉取用户在微信支付交易记录中针对你的支付记录进行的评价内容。商户可结合商户系统逻辑对该内容数据进行存储、分析、展示、客服回访以及其他使用。如商户业务对评价内容有依赖,可主动引导用户进入微信支付交易记录进行评价。 24 | 25 | 26 | See: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_99&index=12 27 | 28 | POST https://api.mch.weixin.qq.com/billcommentsp/batchquerycomment 29 | */ 30 | func BatchQueryComment(ctx *wxpay.WXPay, params map[string]string) (result []byte, err error) { 31 | return ctx.Client.HTTPPost("/billcommentsp/batchquerycomment", params, true) 32 | } 33 | -------------------------------------------------------------------------------- /util/randstring.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package util 16 | 17 | import ( 18 | "math/rand" 19 | "time" 20 | ) 21 | 22 | const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" 23 | 24 | // GetRandStringWithCharset 获取指定字符集 下 指定长度的随机字符串 25 | func GetRandStringWithCharset(length int, charset string) string { 26 | seededRand := rand.New(rand.NewSource(time.Now().UnixNano())) 27 | 28 | b := make([]byte, length) 29 | for i := range b { 30 | b[i] = charset[seededRand.Intn(len(charset))] 31 | } 32 | return string(b) 33 | } 34 | 35 | // GetRandString 获取指定长度的随机字符串 36 | func GetRandString(length int) string { 37 | return GetRandStringWithCharset(length, charset) 38 | } 39 | -------------------------------------------------------------------------------- /apis/download/download_fund_flow.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package download 下载 相关 16 | package download 17 | 18 | import "github.com/fastwego/wxpay" 19 | 20 | /* 21 | 下载资金账单 22 | 23 | 24 | 商户可以通过该接口下载自2017年6月1日起 的历史资金流水账单。 25 | 26 | 说明: 27 | 28 | 1、资金账单中的数据反映的是商户微信账户资金变动情况; 29 | 30 | 2、当日账单在次日上午9点开始生成,建议商户在上午10点以后获取; 31 | 32 | 3、资金账单中涉及金额的字段单位为“元”。 33 | 34 | 35 | See: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_18&index=9 36 | 37 | POST https://api.mch.weixin.qq.com/pay/downloadfundflow 38 | */ 39 | func DownloadFundFlow(ctx *wxpay.WXPay, params map[string]string) (result []byte, err error) { 40 | return ctx.Client.HTTPPost("/pay/downloadfundflow", params, true) 41 | } 42 | -------------------------------------------------------------------------------- /apis/corp_pay/get_public_key.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package corp_pay 企业付款 16 | package corp_pay 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 获取 RSA 加密公钥 25 | 26 | 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_7&index=4 29 | 30 | POST https://fraud.mch.weixin.qq.com/risk/getpublickey 31 | */ 32 | func GetPublicKey(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/risk/getpublickey", params, true) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/corp_pay/transfers.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package corp_pay 企业付款 16 | package corp_pay 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 企业付款 零钱 25 | 26 | 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2 29 | 30 | POST https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers 31 | */ 32 | func Transfers(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/mmpaymkttransfers/promotion/transfers", params, true) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/dev_util/get_sign_key.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package dev_util 开发辅助 16 | package dev_util 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 沙箱获取 signKey 25 | 26 | 验收仿真测试系统的API验签密钥需从API获取 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=23_1&index=2 29 | 30 | POST https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey 31 | */ 32 | func GetSignKey(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/pay/getsignkey", params, false) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/order/unified_order.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package order 订单相关 16 | package order 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 统一下单 25 | 26 | 商户系统先调用该接口在微信支付服务后台生成预支付交易单,返回正确的预支付交易会话标识后再在APP里面调起支付。 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1 29 | 30 | POST https://api.mch.weixin.qq.com/pay/unifiedorder 31 | */ 32 | func UnifiedOrder(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/pay/unifiedorder", params, false) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /test/test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package test 模拟微信服务器 测试 16 | package test 17 | 18 | import ( 19 | "net/http" 20 | "net/http/httptest" 21 | "sync" 22 | 23 | "github.com/fastwego/wxpay" 24 | ) 25 | 26 | var MockWXPay *wxpay.WXPay 27 | var MockSvr *httptest.Server 28 | var MockSvrHandler *http.ServeMux 29 | var onceSetup sync.Once 30 | 31 | func Setup() { 32 | 33 | onceSetup.Do(func() { 34 | MockWXPay = wxpay.New(wxpay.Config{ 35 | Appid: "APPID", 36 | Mchid: "1233978202", 37 | ApiKey: "KEY", 38 | }) 39 | 40 | // Mock Server 41 | MockSvrHandler = http.NewServeMux() 42 | MockSvr = httptest.NewServer(MockSvrHandler) 43 | wxpay.WXPayServerUrl = MockSvr.URL // 拦截发往微信服务器的请求 44 | wxpay.RSAServerUrl = MockSvr.URL 45 | }) 46 | } 47 | -------------------------------------------------------------------------------- /apis/corp_pay/query_bank.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package corp_pay 企业付款 16 | package corp_pay 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 查询 企业付款到银行卡 25 | 26 | 用于对商户企业付款到银行卡操作进行结果查询,返回付款操作详细结果。 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_3 29 | 30 | POST https://api.mch.weixin.qq.com/mmpaysptrans/query_bank 31 | */ 32 | func QueryBank(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/mmpaysptrans/query_bank", params, true) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/coupon/query_coupons_info.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package coupon 代金券 16 | package coupon 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 查询代金券信息 25 | 26 | 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_5&index=6 29 | 30 | POST https://api.mch.weixin.qq.com/mmpaymkttransfers/querycouponsinfo 31 | */ 32 | func QueryCouponsInfo(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/mmpaymkttransfers/querycouponsinfo", params, false) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/coupon/query_coupon_stock.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package coupon 代金券 16 | package coupon 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 查询代金券批次 25 | 26 | 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_4&index=5 29 | 30 | POST https://api.mch.weixin.qq.com/mmpaymkttransfers/query_coupon_stock 31 | */ 32 | func QueryCouponStock(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/mmpaymkttransfers/query_coupon_stock", params, false) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/refund/refund_query.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package refund 退款 相关 16 | package refund 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 查询退款 25 | 26 | 当提交退款申请后,通过调用该接口查询退款状态。退款有一定延时,用零钱支付的退款20分钟内到账,银行卡支付的退款3个工作日后重新查询退款状态。 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_5&index=7 29 | 30 | POST https://api.mch.weixin.qq.com/pay/refundquery 31 | */ 32 | func RefundQuery(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/pay/refundquery", params, false) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/native/short_url.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package native Native 支付 16 | package native 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 转换短链接 25 | 26 | 该接口主要用于Native支付模式一中的二维码链接转成短链接(weixin://wxpay/s/XXXXXX),减小二维码数据量,提升扫描速度和精确度。 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_9&index=10 29 | 30 | POST https://api.mch.weixin.qq.com/tools/shorturl 31 | */ 32 | func ShortUrl(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/tools/shorturl", params, false) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/lucky_money/get_hb_info.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package lucky_money 现金红包 16 | package lucky_money 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 查询红包记录 25 | 26 | 用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_6&index=5 29 | 30 | POST https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo 31 | */ 32 | func GetHBInfo(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/mmpaymkttransfers/gethbinfo", params, true) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/lucky_money/send_miniprogram_hb.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package lucky_money 现金红包 16 | package lucky_money 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 小程序红包-发放 25 | 26 | 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=18_2&index=3 29 | 30 | POST hhttps://api.mch.weixin.qq.com/mmpaymkttransfers/sendminiprogramhb 31 | */ 32 | func SendMiniprogramHB(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/mmpaymkttransfers/sendminiprogramhb", params, true) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/corp_pay/pay_bank.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package corp_pay 企业付款 16 | package corp_pay 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 企业付款到银行卡 25 | 26 | 企业付款业务是基于微信支付商户平台的资金管理能力,为了协助商户方便地实现企业向银行卡付款,针对部分有开发能力的商户,提供通过API完成企业付款到银行卡的功能。 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_2 29 | 30 | POST https://api.mch.weixin.qq.com/mmpaysptrans/pay_bank 31 | */ 32 | func PayBank(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/mmpaysptrans/pay_bank", params, true) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/micropay/auth_code_to_open_id.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package micropay 付款码支付 16 | package micropay 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 付款码查询openid 25 | 26 | 通过付款码查询公众号Openid,调用查询后,该付款码只能由此商户号发起扣款,直至付款码更新。 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_13&index=9 29 | 30 | POST https://api.mch.weixin.qq.com/tools/authcodetoopenid 31 | */ 32 | func AuthCodeToOpenId(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/tools/authcodetoopenid", params, false) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/refund/refund.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package refund 退款 相关 16 | package refund 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 退款 25 | 26 | 当交易发生之后一段时间内,由于买家或者卖家的原因需要退款时,卖家可以通过退款接口将支付款退还给买家,微信支付将在收到退款请求并且验证成功之后,按照退款规则将支付款按原路退到买家帐号上。 27 | 28 | 29 | See: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_4&index=6 30 | 31 | POST https://api.mch.weixin.qq.com/secapi/pay/refund 32 | */ 33 | func Refund(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 34 | 35 | resp, err := ctx.Client.HTTPPost("/secapi/pay/refund", params, true) 36 | if err != nil { 37 | return 38 | } 39 | 40 | result, err = util.XML2Map(resp) 41 | if err != nil { 42 | return 43 | } 44 | return 45 | } 46 | -------------------------------------------------------------------------------- /apis/profit_sharing/profit_sharing_query.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package profit_sharing 分账 16 | package profit_sharing 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 查询分账结果 25 | 26 | 发起分账请求后,可调用此接口查询分账结果;发起分账完结请求后,可调用此接口查询分账完结的执行结果。 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_2&index=3 29 | 30 | POST https://api.mch.weixin.qq.com/pay/profitsharingquery 31 | */ 32 | func ProfitSharingQuery(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/pay/profitsharingquery", params, false) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/coupon/send_coupon.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package coupon 代金券 16 | package coupon 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 发放代金券 25 | 26 | 用于商户主动调用接口给用户发放代金券的场景,已做防小号处理,给小号发放代金券将返回错误码。 27 | 28 | 注意:通过接口发放的代金券不会进入微信卡包 29 | 30 | See: https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_3&index=4 31 | 32 | POST https://api.mch.weixin.qq.com/mmpaymkttransfers/send_coupon 33 | */ 34 | func SendCoupon(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 35 | 36 | resp, err := ctx.Client.HTTPPost("/mmpaymkttransfers/send_coupon", params, false) 37 | if err != nil { 38 | return 39 | } 40 | 41 | result, err = util.XML2Map(resp) 42 | if err != nil { 43 | return 44 | } 45 | return 46 | } 47 | -------------------------------------------------------------------------------- /apis/profit_sharing/profit_sharing.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package profit_sharing 分账 16 | package profit_sharing 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 请求单次分账 25 | 26 | 单次分账请求按照传入的分账接收方账号和资金进行分账,同时会将订单剩余的待分账金额解冻给本商户。故操作成功后,订单不能再进行分账,也不能进行分账完结。 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_1&index=1 29 | 30 | POST https://api.mch.weixin.qq.com/secapi/pay/profitsharing 31 | */ 32 | func ProfitSharing(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/secapi/pay/profitsharing", params, true) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/profit_sharing/profit_sharing_add_receiver.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package profit_sharing 分账 16 | package profit_sharing 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 添加分账接收方 25 | 26 | 商户发起添加分账接收方请求,后续可通过发起分账请求将结算后的钱分到该分账接收方。 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_3&index=4 29 | 30 | POST https://api.mch.weixin.qq.com/pay/profitsharingaddreceiver 31 | */ 32 | func ProfitSharingAddReceiver(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/pay/profitsharingaddreceiver", params, false) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/order/close_order.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package order 订单相关 16 | package order 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 关闭订单 25 | 26 | 以下情况需要调用关单接口:商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付;系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口。 27 | 28 | 注意:订单生成后不能马上调用关单接口,最短调用时间间隔为5分钟。 29 | 30 | See: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_3&index=5 31 | 32 | POST https://api.mch.weixin.qq.com/pay/closeorder 33 | */ 34 | func CloseOrder(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 35 | 36 | resp, err := ctx.Client.HTTPPost("/pay/closeorder", params, false) 37 | if err != nil { 38 | return 39 | } 40 | 41 | result, err = util.XML2Map(resp) 42 | if err != nil { 43 | return 44 | } 45 | return 46 | } 47 | -------------------------------------------------------------------------------- /apis/profit_sharing/profit_sharing_remove_receiver.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package profit_sharing 分账 16 | package profit_sharing 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 删除分账接收方 25 | 26 | 商户发起删除分账接收方请求,删除后不支持将结算后的钱分到该分账接收方 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_4&index=5 29 | 30 | POST https://api.mch.weixin.qq.com/pay/profitsharingremovereceiver 31 | */ 32 | func ProfitSharingRemoveReceiver(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/pay/profitsharingremovereceiver", params, false) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/corp_pay/get_transfer_info.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package corp_pay 企业付款 16 | package corp_pay 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 查询 企业付款 零钱 25 | 26 | 用于商户的企业付款操作进行结果查询,返回付款操作详细结果。 27 | 28 | 查询企业付款API只支持查询30天内的订单,30天之前的订单请登录商户平台查询。 29 | 30 | See: https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_3 31 | 32 | POST https://api.mch.weixin.qq.com/mmpaymkttransfers/gettransferinfo 33 | */ 34 | func GetTransferInfo(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 35 | 36 | resp, err := ctx.Client.HTTPPost("/mmpaymkttransfers/gettransferinfo", params, true) 37 | if err != nil { 38 | return 39 | } 40 | 41 | result, err = util.XML2Map(resp) 42 | if err != nil { 43 | return 44 | } 45 | return 46 | } 47 | -------------------------------------------------------------------------------- /apis/dev_util/report.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package dev_util 开发辅助 16 | package dev_util 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 交易保障 上报 25 | 26 | 商户在调用微信支付提供的相关接口时,会得到微信支付返回的相关信息以及获得整个接口的响应时间。为提高整体的服务水平,协助商户一起提高服务质量,微信支付提供了相关接口调用耗时和返回信息的主动上报接口,微信支付可以根据商户侧上报的数据进一步优化网络部署,完善服务监控,和商户更好的协作为用户提供更好的业务体验。 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_8&index=10 29 | 30 | POST https://api.mch.weixin.qq.com/payitil/report 31 | */ 32 | func Report(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/payitil/report", params, false) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/profit_sharing/profit_sharing_return_query.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package profit_sharing 分账 16 | package profit_sharing 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 回退结果查询 25 | 26 | ● 商户需要核实回退结果,可调用此接口查询回退结果。 27 | 28 | ● 如果分账回退接口返回状态为处理中,可调用此接口查询回退结果 29 | 30 | See: https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_8&index=8 31 | 32 | POST https://api.mch.weixin.qq.com/pay/profitsharingreturnquery 33 | */ 34 | func ProfitSharingReturnQuery(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 35 | 36 | resp, err := ctx.Client.HTTPPost("/pay/profitsharingreturnquery", params, false) 37 | if err != nil { 38 | return 39 | } 40 | 41 | result, err = util.XML2Map(resp) 42 | if err != nil { 43 | return 44 | } 45 | return 46 | } 47 | -------------------------------------------------------------------------------- /apis/lucky_money/send_group_red_pack.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package lucky_money 现金红包 16 | package lucky_money 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 发放裂变红包 25 | 26 | 裂变红包:一次可以发放一组红包。首先领取的用户为种子用户,种子用户领取一组红包当中的一个,并可以通过社交分享将剩下的红包给其他用户。裂变红包充分利用了人际传播的优势。 27 | 28 | See: https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4 29 | 30 | POST https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack 31 | */ 32 | func SendGroupRedPack(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 33 | 34 | resp, err := ctx.Client.HTTPPost("/mmpaymkttransfers/sendgroupredpack", params, true) 35 | if err != nil { 36 | return 37 | } 38 | 39 | result, err = util.XML2Map(resp) 40 | if err != nil { 41 | return 42 | } 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /apis/micropay/reverse.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package micropay 付款码支付 16 | package micropay 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 撤销订单 25 | 26 | 支付交易返回失败或支付系统超时,调用该接口撤销交易。如果此订单用户支付失败,微信支付系统会将此订单关闭;如果用户支付成功,微信支付系统会将此订单资金退还给用户。 27 | 28 | 注意:7天以内的交易单可调用撤销,其他正常支付的单如需实现相同功能请调用申请退款API。提交支付交易后调用【查询订单API】,没有明确的支付结果再调用【撤销订单API】。 29 | 30 | 31 | See: https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_11&index=3 32 | 33 | POST https://api.mch.weixin.qq.com/secapi/pay/reverse 34 | */ 35 | func Reverse(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 36 | 37 | resp, err := ctx.Client.HTTPPost("/secapi/pay/reverse", params, true) 38 | if err != nil { 39 | return 40 | } 41 | 42 | result, err = util.XML2Map(resp) 43 | if err != nil { 44 | return 45 | } 46 | return 47 | } 48 | -------------------------------------------------------------------------------- /apis/profit_sharing/profit_sharing_finish.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package profit_sharing 分账 16 | package profit_sharing 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 完结分账 25 | 26 | 1、不需要进行分账的订单,可直接调用本接口将订单的金额全部解冻给本商户 27 | 2、调用多次分账接口后,需要解冻剩余资金时,调用本接口将剩余的分账金额全部解冻给特约商户 28 | 3、已调用请求单次分账后,剩余待分账金额为零,不需要再调用此接口。 29 | 30 | See: https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_5&index=6 31 | 32 | POST https://api.mch.weixin.qq.com/secapi/pay/profitsharingfinish 33 | */ 34 | func ProfitSharingFinish(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 35 | 36 | resp, err := ctx.Client.HTTPPost("/secapi/pay/profitsharingfinish", params, true) 37 | if err != nil { 38 | return 39 | } 40 | 41 | result, err = util.XML2Map(resp) 42 | if err != nil { 43 | return 44 | } 45 | return 46 | } 47 | -------------------------------------------------------------------------------- /apis/download/download_bill.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package download 下载 相关 16 | package download 17 | 18 | import "github.com/fastwego/wxpay" 19 | 20 | /* 21 | 下载交易账单 22 | 23 | 商户可以通过该接口下载历史交易清单。比如掉单、系统错误等导致商户侧和微信侧数据不一致,通过对账单核对后可校正支付状态。 24 | 25 | 注意: 26 | 27 | 1、微信侧未成功下单的交易不会出现在对账单中。支付成功后撤销的交易会出现在对账单中,跟原支付单订单号一致; 28 | 29 | 2、微信在次日9点启动生成前一天的对账单,建议商户10点后再获取; 30 | 31 | 3、对账单中涉及金额的字段单位为“元”。 32 | 33 | 4、对账单接口只能下载三个月以内的账单。 34 | 35 | 5、对账单是以商户号纬度来生成的,如一个商户号与多个appid有绑定关系,则使用其中任何一个appid都可以请求下载对账单。对账单中的appid取自交易时候提交的appid,与请求下载对账单时使用的appid无关。 36 | 37 | 6、自2018年起入驻的商户默认是开通免充值券后的结算对账单。 38 | 39 | See: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_6&index=8 40 | 41 | POST https://api.mch.weixin.qq.com/pay/downloadbill 42 | */ 43 | func DownloadBill(ctx *wxpay.WXPay, params map[string]string) (result []byte, err error) { 44 | return ctx.Client.HTTPPost("/pay/downloadbill", params, false) 45 | } 46 | -------------------------------------------------------------------------------- /apis/order/order_query.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package order 订单相关 16 | package order 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 查询订单 25 | 26 | 该接口提供所有微信支付订单的查询,商户可以通过该接口主动查询订单状态,完成下一步的业务逻辑。 27 | 28 | 需要调用查询接口的情况: 29 | 30 | ◆ 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知; 31 | 32 | ◆ 调用支付接口后,返回系统错误或未知交易状态情况; 33 | 34 | ◆ 调用被扫支付API,返回USERPAYING的状态; 35 | 36 | ◆ 调用关单或撤销接口API之前,需确认支付状态; 37 | 38 | See: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_2&index=4 39 | 40 | POST https://api.mch.weixin.qq.com/pay/orderquery 41 | */ 42 | func OrderQuery(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 43 | 44 | resp, err := ctx.Client.HTTPPost("/pay/orderquery", params, false) 45 | if err != nil { 46 | return 47 | } 48 | 49 | result, err = util.XML2Map(resp) 50 | if err != nil { 51 | return 52 | } 53 | return 54 | } 55 | -------------------------------------------------------------------------------- /apis/lucky_money/send_red_pack.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package lucky_money 现金红包 16 | package lucky_money 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 发放红包接口 25 | 26 | 1.发送频率限制------默认1800/min 27 | 28 | 2.发送个数上限------默认1800/min 29 | 30 | 3.场景金额限制------默认红包金额为1-200元,如有需要,可前往商户平台进行设置和申请 31 | 32 | 4.其他限制------商户单日出资金额上限--100万元;单用户单日收款金额上限--1000元;单用户可领取红包个数上限--10个; 33 | 34 | 35 | 36 | See: https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3 37 | 38 | POST https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack 39 | */ 40 | func SendRedPack(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 41 | 42 | resp, err := ctx.Client.HTTPPost("/mmpaymkttransfers/sendredpack", params, true) 43 | if err != nil { 44 | return 45 | } 46 | 47 | result, err = util.XML2Map(resp) 48 | if err != nil { 49 | return 50 | } 51 | return 52 | } 53 | -------------------------------------------------------------------------------- /apis/profit_sharing/multi_profit_sharing.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package profit_sharing 分账 16 | package profit_sharing 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 请求多次分账 25 | 26 | ● 微信订单支付成功后,商户发起分账请求,将结算后的钱分到分账接收方。多次分账请求仅会按照传入的分账接收方进行分账,不会对剩余的金额进行任何操作。故操作成功后,在待分账金额不等于零时,订单依旧能够再次进行分账。 27 | 28 | ● 多次分账,可以将本商户作为分账接收方直接传入,实现释放资金给本商户的功能 29 | 30 | ● 对同一笔订单最多能发起20次多次分账请求 31 | 32 | 33 | 34 | See: https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_6&index=2 35 | 36 | POST https://api.mch.weixin.qq.com/secapi/pay/multiprofitsharing 37 | */ 38 | func MultiProfitSharing(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 39 | 40 | resp, err := ctx.Client.HTTPPost("/secapi/pay/multiprofitsharing", params, true) 41 | if err != nil { 42 | return 43 | } 44 | 45 | result, err = util.XML2Map(resp) 46 | if err != nil { 47 | return 48 | } 49 | return 50 | } 51 | -------------------------------------------------------------------------------- /apis/profit_sharing/profit_sharing_return.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package profit_sharing 分账 16 | package profit_sharing 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 分账回退 25 | 26 | ● 对订单进行退款时,如果订单已经分账,可以先调用此接口将指定的金额从分账接收方(仅限商户类型的分账接收方)回退给本商户,然后再退款。 27 | 28 | ● 回退以原分账请求为依据,可以对分给分账接收方的金额进行多次回退,只要满足累计回退不超过该请求中分给接收方的金额。 29 | 30 | ● 此接口采用同步处理模式,即在接收到商户请求后,会实时返回处理结果 31 | 32 | ● 此功能需要接收方在商户平台-交易中心-分账-分账接收设置下,开启同意分账回退后,才能使用。 33 | 34 | See: https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_7&index=7 35 | 36 | POST https://api.mch.weixin.qq.com/secapi/pay/profitsharingreturn 37 | */ 38 | func ProfitSharingReturn(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 39 | 40 | resp, err := ctx.Client.HTTPPost("/secapi/pay/profitsharingreturn", params, true) 41 | if err != nil { 42 | return 43 | } 44 | 45 | result, err = util.XML2Map(resp) 46 | if err != nil { 47 | return 48 | } 49 | return 50 | } 51 | -------------------------------------------------------------------------------- /apis/micropay/micro_pay.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package micropay 付款码支付 16 | package micropay 17 | 18 | import ( 19 | "github.com/fastwego/wxpay" 20 | "github.com/fastwego/wxpay/util" 21 | ) 22 | 23 | /* 24 | 付款码支付 25 | 26 | 27 | 收银员使用扫码设备读取微信用户付款码以后,二维码或条码信息会传送至商户收银台,由商户收银台或者商户后台调用该接口发起支付。 28 | 29 | 提醒1:提交支付请求后微信会同步返回支付结果。当返回结果为“系统错误”时,商户系统等待5秒后调用【查询订单API】,查询支付实际交易结果;当返回结果为“USERPAYING”时,商户系统可设置间隔时间(建议10秒)重新查询支付结果,直到支付成功或超时(建议30秒); 30 | 31 | 提醒2:在调用查询接口返回后,如果交易状况不明晰,请调用【撤销订单API】,此时如果交易失败则关闭订单,该单不能再支付成功;如果交易成功,则将扣款退回到用户账户。当撤销无返回或错误时,请再次调用。注意:请勿扣款后立即调用【撤销订单API】,建议至少15秒后再调用。撤销订单API需要双向证书。 32 | 33 | 34 | See: https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_10&index=1# 35 | 36 | POST https://api.mch.weixin.qq.com/pay/micropay 37 | */ 38 | func MicroPay(ctx *wxpay.WXPay, params map[string]string) (result map[string]string, err error) { 39 | 40 | resp, err := ctx.Client.HTTPPost("/pay/micropay", params, false) 41 | if err != nil { 42 | return 43 | } 44 | 45 | result, err = util.XML2Map(resp) 46 | if err != nil { 47 | return 48 | } 49 | return 50 | } 51 | -------------------------------------------------------------------------------- /types/types.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | const ( 18 | AccountTypeBasic = "Basic" 19 | AccountTypeOperation = "Operation" 20 | AccountTypeFees = "Fees" 21 | ) 22 | 23 | const ( 24 | FeeTypeCNY = "CNY" 25 | ) 26 | 27 | const ( 28 | SignTypeHMACSHA256 = "HMAC-SHA256" 29 | SignTypeMD5 = "MD5" 30 | ) 31 | 32 | const ( 33 | TradeTypeJSAPI = "JSAPI" //JSAPI--JSAPI支付(或小程序支付) 34 | TradeTypeNATIVE = "NATIVE" //NATIVE--Native支付 35 | TradeTypeAPP = "APP" //APP--app支付 36 | TradeTypeMWEB = "MWEB" //MWEB--H5支付,不同trade_type决定了调起支付的方式,请根据支付产品正确上传 37 | TradeTypeMICROPAY = "MICROPAY" //MICROPAY--付款码支付,付款码支付有单独的支付接口,所以接口不需要上传,该字段在对账单中会出现 38 | ) 39 | 40 | const ( 41 | BillTypeALL = "ALL" // ALL(默认值),返回当日所有订单信息(不含充值退款订单) 42 | BillTypeSUCCESS = "SUCCESS" // SUCCESS,返回当日成功支付的订单(不含充值退款订单) 43 | BillTypeREFUND = "REFUND" // REFUND,返回当日退款订单(不含充值退款订单) 44 | BillTypeRECHARGE_REFUND = "RECHARGE_REFUND" //RECHARGE_REFUND,返回当日充值退款订单 45 | ) 46 | 47 | const ( 48 | TarType = "GZIP" 49 | ) 50 | -------------------------------------------------------------------------------- /util/util.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package util 16 | 17 | import ( 18 | "encoding/xml" 19 | "reflect" 20 | "strings" 21 | ) 22 | 23 | type CDATA string 24 | 25 | func (c CDATA) MarshalXML(e *xml.Encoder, start xml.StartElement) error { 26 | return e.EncodeElement(struct { 27 | string `xml:",cdata"` 28 | }{string(c)}, start) 29 | } 30 | 31 | func StructToMapByXMLTag(item interface{}, result map[string]interface{}) { 32 | 33 | if item == nil { 34 | return 35 | } 36 | 37 | v := reflect.TypeOf(item) 38 | reflectValue := reflect.ValueOf(item) 39 | reflectValue = reflect.Indirect(reflectValue) 40 | 41 | if v.Kind() == reflect.Ptr { 42 | v = v.Elem() 43 | } 44 | 45 | for i := 0; i < v.NumField(); i++ { 46 | tag := v.Field(i).Tag.Get("xml") 47 | 48 | if strings.Contains(tag, ",") { 49 | split := strings.Split(tag, ",") 50 | tag = strings.TrimSpace(split[0]) 51 | } 52 | 53 | field := reflectValue.Field(i).Interface() 54 | 55 | if v.Field(i).Type.Kind() == reflect.Struct { 56 | StructToMapByXMLTag(field, result) 57 | } else if tag != "" && tag != "-" { 58 | result[tag] = field 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /util/randstring_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package util 16 | 17 | import ( 18 | "fmt" 19 | "testing" 20 | ) 21 | 22 | func TestGetRandString(t *testing.T) { 23 | type args struct { 24 | length int 25 | } 26 | tests := []struct { 27 | name string 28 | args args 29 | want string 30 | wantLen int 31 | }{ 32 | {name: "case1", args: args{length: 6}, wantLen: 6}, 33 | } 34 | for _, tt := range tests { 35 | t.Run(tt.name, func(t *testing.T) { 36 | got := GetRandString(tt.args.length) 37 | if len(got) != tt.wantLen { 38 | t.Errorf("GetRandString() = %v, want %v", got, tt.want) 39 | } 40 | 41 | fmt.Println(got) 42 | }) 43 | } 44 | } 45 | 46 | func TestGetRandStringWithCharset(t *testing.T) { 47 | type args struct { 48 | length int 49 | charset string 50 | } 51 | tests := []struct { 52 | name string 53 | args args 54 | want string 55 | wantLen int 56 | }{ 57 | {name: "case1", args: args{length: 6, charset: "0x0x0x"}, wantLen: 6}, 58 | } 59 | for _, tt := range tests { 60 | t.Run(tt.name, func(t *testing.T) { 61 | got := GetRandStringWithCharset(tt.args.length, tt.args.charset) 62 | if len(got) != tt.wantLen { 63 | t.Errorf("GetRandStringWithCharset() = %v, want %v", got, tt.want) 64 | } 65 | fmt.Println(got) 66 | }) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /apis/dev_util/report_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package dev_util 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestReport(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/payitil/report", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := Report(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("Report() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/refund/refund_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package refund 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestRefund(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/secapi/pay/refund", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := Refund(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("Refund() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/micropay/micro_pay_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package micropay 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestMicroPay(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/pay/micropay", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := MicroPay(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("MicroPay() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/micropay/reverse_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package micropay 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestReverse(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/secapi/pay/reverse", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := Reverse(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("Reverse() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/native/short_url_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package native 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestShortUrl(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/tools/shorturl", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := ShortUrl(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("ShortUrl() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/corp_pay/pay_bank_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package corp_pay 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestPayBank(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/mmpaysptrans/pay_bank", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := PayBank(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("PayBank() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/order/close_order_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package order 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestCloseOrder(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/pay/closeorder", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := CloseOrder(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("CloseOrder() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/order/order_query_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package order 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestOrderQuery(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/pay/orderquery", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := OrderQuery(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("OrderQuery() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/dev_util/get_sign_key_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package dev_util 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestGetSignKey(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/pay/getsignkey", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := GetSignKey(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("GetSignKey() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/refund/refund_query_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package refund 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestRefundQuery(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/pay/refundquery", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := RefundQuery(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("RefundQuery() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/corp_pay/query_bank_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package corp_pay 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestQueryBank(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/mmpaysptrans/query_bank", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := QueryBank(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("QueryBank() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/order/unified_order_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package order 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestUnifiedOrder(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/pay/unifiedorder", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := UnifiedOrder(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("UnifiedOrder() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/coupon/send_coupon_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package coupon 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestSendCoupon(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/mmpaymkttransfers/send_coupon", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := SendCoupon(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("SendCoupon() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/download/download_bill_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package download 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestDownloadBill(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/pay/downloadbill", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult []byte 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: mockResp["case1"], wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := DownloadBill(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("BatchQueryComment() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult, tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/corp_pay/get_public_key_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package corp_pay 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestGetPublicKey(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/risk/getpublickey", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := GetPublicKey(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("GetPublicKey() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/lucky_money/get_hb_info_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package lucky_money 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestGetHBInfo(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/mmpaymkttransfers/gethbinfo", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := GetHBInfo(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("GetHBInfo() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /util/util_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package util 16 | 17 | import ( 18 | "encoding/xml" 19 | "testing" 20 | 21 | "github.com/fastwego/wxpay/types" 22 | ) 23 | 24 | func TestStructToMapByXMLTag(t *testing.T) { 25 | 26 | type T1 struct { 27 | B string `xml:"b"` 28 | } 29 | 30 | type T struct { 31 | XMLName xml.Name `xml:"xml"` 32 | Appid string `xml:"appid"` // 应用ID 33 | Mchid string `xml:"mch_id"` // 商户号 34 | NonceStr string `xml:"nonce_str"` // 随机字符串 35 | Sign string `xml:"sign"` // 签名 36 | SignType string `xml:"sign_type,omitempty"` // 签名类型 37 | T1 38 | } 39 | 40 | item1 := T{ 41 | Appid: "100", 42 | SignType: types.SignTypeMD5, 43 | } 44 | item1.T1 = T1{B: "200"} 45 | 46 | type args struct { 47 | item interface{} 48 | result map[string]interface{} 49 | } 50 | tests := []struct { 51 | name string 52 | args args 53 | }{ 54 | {name: "case1", args: args{ 55 | item: item1, 56 | result: map[string]interface{}{}, 57 | }}, 58 | } 59 | for _, tt := range tests { 60 | t.Run(tt.name, func(t *testing.T) { 61 | StructToMapByXMLTag(tt.args.item, tt.args.result) 62 | 63 | s, ok := tt.args.result["appid"].(string) 64 | if !ok { 65 | t.Error("Not OK") 66 | return 67 | } 68 | 69 | if s != "100" { 70 | t.Error("not equal") 71 | return 72 | } 73 | 74 | sign_type, ok := tt.args.result["sign_type"].(string) 75 | if !ok { 76 | t.Error("Not OK") 77 | return 78 | } 79 | 80 | if sign_type != types.SignTypeMD5 { 81 | t.Error("sign_type not equal") 82 | return 83 | } 84 | }) 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /apis/corp_pay/transfers_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package corp_pay 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestTransfers(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/mmpaymkttransfers/promotion/transfers", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := Transfers(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("Transfers() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/download/download_fund_flow_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package download 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestDownloadFundFlow(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/pay/downloadfundflow", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult []byte 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: mockResp["case1"], wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := DownloadFundFlow(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("BatchQueryComment() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult, tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/lucky_money/send_red_pack_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package lucky_money 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestSendRedPack(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/mmpaymkttransfers/sendredpack", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := SendRedPack(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("SendRedPack() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/micropay/auth_code_to_open_id_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package micropay 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestAuthCodeToOpenId(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/tools/authcodetoopenid", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := AuthCodeToOpenId(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("AuthCodeToOpenId() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/profit_sharing/profit_sharing_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package profit_sharing 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestProfitSharing(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/secapi/pay/profitsharing", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := ProfitSharing(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("ProfitSharing() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/corp_pay/get_transfer_info_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package corp_pay 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestGetTransferInfo(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/mmpaymkttransfers/gettransferinfo", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := GetTransferInfo(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("GetTransferInfo() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/coupon/query_coupons_info_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package coupon 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestQueryCouponsInfo(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/mmpaymkttransfers/querycouponsinfo", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := QueryCouponsInfo(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("QueryCouponsInfo() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/download/batch_query_comment_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package download 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestBatchQueryComment(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/billcommentsp/batchquerycomment", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult []byte 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: mockResp["case1"], wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := BatchQueryComment(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("BatchQueryComment() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult, tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/coupon/query_coupon_stock_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package coupon 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestQueryCouponStock(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/mmpaymkttransfers/query_coupon_stock", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := QueryCouponStock(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("QueryCouponStock() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/lucky_money/send_group_red_pack_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package lucky_money 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestSendGroupRedPack(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/mmpaymkttransfers/sendgroupredpack", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := SendGroupRedPack(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("SendGroupRedPack() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/lucky_money/send_miniprogram_hb_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package lucky_money 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestSendMiniprogramHB(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/mmpaymkttransfers/sendminiprogramhb", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := SendMiniprogramHB(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("SendMiniprogramHB() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/profit_sharing/profit_sharing_query_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package profit_sharing 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestProfitSharingQuery(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/pay/profitsharingquery", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := ProfitSharingQuery(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("ProfitSharingQuery() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/profit_sharing/multi_profit_sharing_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package profit_sharing 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestMultiProfitSharing(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/secapi/pay/multiprofitsharing", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := MultiProfitSharing(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("MultiProfitSharing() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/profit_sharing/profit_sharing_finish_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package profit_sharing 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestProfitSharingFinish(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/secapi/pay/profitsharingfinish", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := ProfitSharingFinish(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("ProfitSharingFinish() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/profit_sharing/profit_sharing_return_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package profit_sharing 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestProfitSharingReturn(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/secapi/pay/profitsharingreturn", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := ProfitSharingReturn(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("ProfitSharingReturn() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/profit_sharing/profit_sharing_add_receiver_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package profit_sharing 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestProfitSharingAddReceiver(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/pay/profitsharingaddreceiver", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := ProfitSharingAddReceiver(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("ProfitSharingAddReceiver() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/profit_sharing/profit_sharing_return_query_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package profit_sharing 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestProfitSharingReturnQuery(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/pay/profitsharingreturnquery", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := ProfitSharingReturnQuery(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("ProfitSharingReturnQuery() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /apis/profit_sharing/profit_sharing_remove_receiver_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package profit_sharing 16 | 17 | import ( 18 | "net/http" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/fastwego/wxpay/test" 23 | "github.com/fastwego/wxpay/types" 24 | "github.com/fastwego/wxpay/util" 25 | ) 26 | 27 | func TestProfitSharingRemoveReceiver(t *testing.T) { 28 | test.Setup() 29 | 30 | mockResp := map[string][]byte{ 31 | "case1": []byte(""), 32 | } 33 | var resp []byte 34 | test.MockSvrHandler.HandleFunc("/pay/profitsharingremovereceiver", func(w http.ResponseWriter, r *http.Request) { 35 | w.Write([]byte(resp)) 36 | }) 37 | 38 | type args struct { 39 | params map[string]string 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | wantResult string 45 | wantErr bool 46 | }{ 47 | {name: "case1", args: args{params: map[string]string{ 48 | "appid": test.MockWXPay.Config.Appid, 49 | "mch_id": test.MockWXPay.Config.Mchid, 50 | "nonce_str": util.GetRandString(16), 51 | "sign_type": types.SignTypeHMACSHA256}}, wantResult: "SUCCESS", wantErr: false}, 52 | } 53 | for _, tt := range tests { 54 | t.Run(tt.name, func(t *testing.T) { 55 | resp = mockResp[tt.name] 56 | gotResult, err := ProfitSharingRemoveReceiver(test.MockWXPay, tt.args.params) 57 | if (err != nil) != tt.wantErr { 58 | t.Errorf("ProfitSharingRemoveReceiver() error = %v, wantErr %v", err, tt.wantErr) 59 | return 60 | } 61 | if !reflect.DeepEqual(gotResult["return_code"], tt.wantResult) { 62 | t.Errorf("CloseOrder() gotResult = %v, want %v", gotResult, tt.wantResult) 63 | } 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fastwego/wxpay [beta] 2 | 3 | A fast [wxpay(v2)](https://pay.weixin.qq.com/wiki/doc/api/index.html) development sdk written in Golang 4 | 5 | [![GoDoc](https://pkg.go.dev/badge/github.com/fastwego/wxpay?status.svg)](https://pkg.go.dev/github.com/fastwego/wxpay?tab=doc) 6 | [![Go Report Card](https://goreportcard.com/badge/github.com/fastwego/wxpay)](https://goreportcard.com/report/github.com/fastwego/wxpay) 7 | ## 快速开始 & demo 8 | 9 | ```shell script 10 | go get github.com/fastwego/wxpay 11 | ``` 12 | 13 | ```go 14 | // 微信支付 实例 15 | pay = wxpay.New(wxpay.Config{ 16 | Appid: "APPID", 17 | Mchid: "MCHID", 18 | ApiKey: "APIKEY", 19 | //IsSandBoxMode: true, 20 | Cert: "CERT", 21 | }) 22 | 23 | // 统一下单 24 | params := map[string]string{ 25 | "appid": pay.Config.Appid, 26 | "mch_id": pay.Config.Mchid, 27 | "nonce_str": util.GetRandString(32), 28 | "body": "BODY", 29 | "out_trade_no": "NO.10086", 30 | "total_fee": c.Request.URL.Query().Get("fee"), // 201 31 | "spbill_create_ip": "12.123.14.223", 32 | "notify_url": viper.GetString("NOTIFYURL"), 33 | "trade_type": types.TradeTypeAPP, 34 | } 35 | result, err := order.UnifiedOrder(pay, params) 36 | fmt.Println(result, err) 37 | 38 | if err != nil { 39 | return 40 | } 41 | 42 | // 返回客户端预下单信息 43 | //result["prepay_id"] 44 | 45 | ``` 46 | 47 | 完整演示项目: 48 | 49 | [https://github.com/fastwego/wxpay-demo](https://github.com/fastwego/wxpay-demo) 50 | 51 | 查看所有支持的 [API 列表](./doc/apilist.md) 52 | 53 | ## 架构设计 54 | 55 | ![sdk](./doc/img/sdk.jpg) 56 | 57 | 58 | ## 框架特点 59 | 60 | ### 快速 61 | 62 | 「快」作为框架设计的核心理念,体现在方方面面: 63 | 64 | - 使用 Go 语言,开发快、编译快、部署快、运行快,轻松服务海量用户 65 | - 丰富的[文档](https://pkg.go.dev/github.com/fastwego/wxpay) 和 [演示代码](https://github.com/fastwego/wxpay-demo) ,快速上手 66 | - 独立清晰的模块划分,快速熟悉整个框架,没有意外,一切都是你期望的样子 67 | - 甚至连框架自身的大部分代码也是自动生成的,维护更新快到超乎想象 68 | 69 | ### 符合直觉 70 | 71 | 作为第三方开发框架,尽可能贴合官方文档和设计,不引入新的概念,不给开发者添加学习负担 72 | 73 | ### 官方文档就是最好的文档 74 | 75 | 每个接口的注释都附带官方文档的链接,让你随时翻阅,省时省心 76 | 77 | ### 完备的单元测试 78 | 79 | 100% 覆盖每一个接口,让你每一次调用都信心满满 80 | 81 | ### 活跃的开发者社区 82 | 83 | FastWeGo 是一套完整的微信开发框架,包括公众号、开放平台、微信支付、企业微信、小程序、小游戏等微信服务,拥有庞大的开发者用户群体 84 | 85 | 你遇到的所有问题几乎都可以在社区找到解决方案 86 | 87 | ## 参与贡献 88 | 89 | 欢迎提交 pull request / issue / 文档,一起让微信开发更快更好! 90 | 91 | Faster we go together! 92 | 93 | [加入开发者交流群](https://github.com/fastwego/fastwego.dev#%E5%BC%80%E5%8F%91%E8%80%85%E4%BA%A4%E6%B5%81%E7%BE%A4) 94 | -------------------------------------------------------------------------------- /util/aes_crypto.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package util 16 | 17 | import ( 18 | "bytes" 19 | "crypto/aes" 20 | "errors" 21 | "fmt" 22 | ) 23 | 24 | /* 25 | AES encryption with ECB and PKCS7 padding 26 | 27 | AES算法有AES-128、AES-192、AES-256三种,分别对应的key是 16、24、32字节长度 28 | 29 | 对应的加密解密区块长度BlockSize也是16、24、32字节长度 30 | */ 31 | func AESECBPKCS7Encrypt(pt, key []byte) (encrypted []byte, err error) { 32 | block, err := aes.NewCipher(key) 33 | if err != nil { 34 | panic(err.Error()) 35 | } 36 | mode := NewECBEncrypter(block) 37 | 38 | bufLen := len(pt) 39 | padLen := mode.BlockSize() - (bufLen % mode.BlockSize()) 40 | padText := bytes.Repeat([]byte{byte(padLen)}, padLen) 41 | pt = append(pt, padText...) 42 | ct := make([]byte, len(pt)) 43 | mode.CryptBlocks(ct, pt) 44 | 45 | encrypted = pt 46 | return 47 | } 48 | 49 | /* 50 | AES decryption with ECB and PKCS7 padding 51 | 52 | AES算法有AES-128、AES-192、AES-256三种,分别对应的key是 16、24、32字节长度 53 | 54 | 对应的加密解密区块长度BlockSize也是16、24、32字节长度 55 | */ 56 | func AESECBPKCS7Decrypt(cipherData, key []byte) (decrypted []byte, err error) { 57 | 58 | defer func() { 59 | if r := recover(); r != nil { 60 | err = errors.New(fmt.Sprint(r)) 61 | return 62 | } 63 | }() 64 | 65 | block, err := aes.NewCipher(key) 66 | if err != nil { 67 | panic(err.Error()) 68 | } 69 | mode := NewECBDecrypter(block) 70 | pt := make([]byte, len(cipherData)) 71 | mode.CryptBlocks(pt, cipherData) 72 | 73 | bufLen := len(pt) 74 | if bufLen == 0 { 75 | err = errors.New("invalid padding size") 76 | return 77 | } 78 | 79 | pad := pt[bufLen-1] 80 | padLen := int(pad) 81 | if padLen > bufLen || padLen > mode.BlockSize() { 82 | err = errors.New("invalid padding size") 83 | return 84 | } 85 | 86 | for _, v := range pt[bufLen-padLen : bufLen-1] { 87 | if v != pad { 88 | err = errors.New("invalid padding") 89 | return 90 | } 91 | } 92 | 93 | decrypted = pt[:bufLen-padLen] 94 | 95 | return 96 | } 97 | -------------------------------------------------------------------------------- /wxpay_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package wxpay 16 | 17 | import ( 18 | "net/http" 19 | "net/http/httptest" 20 | "os" 21 | "sync" 22 | "testing" 23 | 24 | "github.com/fastwego/wxpay/types" 25 | ) 26 | 27 | var MockWXPay *WXPay 28 | var MockSvr *httptest.Server 29 | var MockSvrHandler *http.ServeMux 30 | var onceSetup sync.Once 31 | 32 | func TestMain(m *testing.M) { 33 | onceSetup.Do(func() { 34 | MockWXPay = New(Config{ 35 | Appid: "APPID", 36 | Mchid: "MCHID", 37 | ApiKey: "KEY", 38 | }) 39 | 40 | // Mock Server 41 | MockSvrHandler = http.NewServeMux() 42 | MockSvr = httptest.NewServer(MockSvrHandler) 43 | WXPayServerUrl = MockSvr.URL // 拦截发往微信服务器的请求 44 | }) 45 | os.Exit(m.Run()) 46 | } 47 | 48 | func TestWXPay_Sign(t *testing.T) { 49 | type args struct { 50 | params map[string]string 51 | signType string 52 | } 53 | 54 | params := map[string]string{ 55 | "appid": "wxd930ea5d5a258f4f", 56 | "mch_id": "10000100", 57 | "device_info": "1000", 58 | "nonce_str": "ibuaiVcKdpRxkhJA", 59 | "body": "test", 60 | } 61 | tests := []struct { 62 | name string 63 | args args 64 | wantSign string 65 | wantErr bool 66 | }{ 67 | {name: "case1", args: args{params: params, signType: types.SignTypeMD5}, wantSign: "9A0A8659F005D6984697E2CA0A9CF3B7", wantErr: false}, 68 | {name: "case2", args: args{params: params, signType: types.SignTypeHMACSHA256}, wantSign: "6A9AE1657590FD6257D693A078E1C3E4BB6BA4DC30B23E0EE2496E54170DACD6", wantErr: false}, 69 | } 70 | for _, tt := range tests { 71 | t.Run(tt.name, func(t *testing.T) { 72 | wxpay := &WXPay{ 73 | Config: Config{ 74 | ApiKey: "192006250b4c09247ec02edce69f6a2d", 75 | }, 76 | } 77 | gotSign, err := wxpay.Sign(tt.args.params, tt.args.signType) 78 | if (err != nil) != tt.wantErr { 79 | t.Errorf("Sign() error = %v, wantErr %v", err, tt.wantErr) 80 | return 81 | } 82 | if gotSign != tt.wantSign { 83 | t.Errorf("Sign() gotSign = %v, want %v", gotSign, tt.wantSign) 84 | } 85 | }) 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /util/string_map_xml.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package util 16 | 17 | import ( 18 | "bytes" 19 | "encoding/xml" 20 | "io" 21 | ) 22 | 23 | type stringMap map[string]string 24 | 25 | type xmlMapEntry struct { 26 | XMLName xml.Name 27 | Value string `xml:",chardata"` 28 | } 29 | 30 | // MarshalXML marshals the map to XML, with each key in the map being a 31 | // tag and it's corresponding value being it's contents. 32 | func (m stringMap) MarshalXML(e *xml.Encoder, start xml.StartElement) error { 33 | if len(m) == 0 { 34 | return nil 35 | } 36 | 37 | err := e.EncodeToken(start) 38 | if err != nil { 39 | return err 40 | } 41 | 42 | for k, v := range m { 43 | e.Encode(xmlMapEntry{XMLName: xml.Name{Local: k}, Value: v}) 44 | } 45 | 46 | return e.EncodeToken(start.End()) 47 | } 48 | 49 | // UnmarshalXML unmarshals the XML into a map of string to strings, 50 | // creating a key in the map for each tag and setting it's value to the 51 | // tags contents. 52 | // 53 | // The fact this function is on the pointer of stringMap is important, so that 54 | // if m is nil it can be initialized, which is often the case if m is 55 | // nested in another xml structurel. This is also why the first thing done 56 | // on the first line is initialize it. 57 | func (m *stringMap) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { 58 | *m = stringMap{} 59 | for { 60 | var e xmlMapEntry 61 | 62 | err := d.Decode(&e) 63 | if err == io.EOF { 64 | break 65 | } else if err != nil { 66 | return err 67 | } 68 | 69 | (*m)[e.XMLName.Local] = e.Value 70 | } 71 | return nil 72 | } 73 | 74 | func Map2XML(kvs map[string]string) (text []byte, err error) { 75 | text, err = xml.Marshal(stringMap(kvs)) 76 | if err != nil { 77 | return 78 | } 79 | text = bytes.ReplaceAll(text, []byte(``), []byte(``)) 80 | text = bytes.ReplaceAll(text, []byte(``), []byte(``)) 81 | 82 | return 83 | } 84 | 85 | func XML2Map(text []byte) (result map[string]string, err error) { 86 | err = xml.Unmarshal(text, (*stringMap)(&result)) 87 | if err != nil { 88 | return 89 | } 90 | return 91 | } 92 | -------------------------------------------------------------------------------- /wxpay.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /* 16 | Package wxpay 微信支付 17 | */ 18 | package wxpay 19 | 20 | import ( 21 | "crypto/hmac" 22 | "crypto/md5" 23 | "crypto/sha256" 24 | "encoding/hex" 25 | "fmt" 26 | "hash" 27 | "log" 28 | "os" 29 | "sort" 30 | "strings" 31 | 32 | "github.com/fastwego/wxpay/types" 33 | ) 34 | 35 | /* 36 | 微信支付 实例 37 | */ 38 | type WXPay struct { 39 | Config Config 40 | Client Client 41 | Server Server 42 | Logger *log.Logger 43 | } 44 | 45 | /* 46 | 微信支付配置 47 | */ 48 | type Config struct { 49 | Appid string 50 | Mchid string // 商户 id 51 | ApiKey string // 商户 api key 52 | IsSandboxMode bool // 是否开启沙箱模式 53 | Cert string // 证书路径 54 | } 55 | 56 | /* 57 | 创建 实例 58 | */ 59 | func New(config Config) (wxpay *WXPay) { 60 | instance := WXPay{ 61 | Config: config, 62 | } 63 | 64 | instance.Client = Client{Ctx: &instance} 65 | instance.Server = Server{Ctx: &instance} 66 | 67 | instance.Logger = log.New(os.Stdout, "[WXPay] ", log.LstdFlags|log.Llongfile) 68 | 69 | return &instance 70 | } 71 | 72 | /* 73 | 74 | 参数签名 75 | 76 | See: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=4_3 77 | */ 78 | func (wxpay *WXPay) Sign(params map[string]string, signType string) (sign string, err error) { 79 | 80 | var kvs []string 81 | for k, v := range params { 82 | if len(v) > 0 && strings.ToLower(k) != "sign" { 83 | kvs = append(kvs, fmt.Sprintf("%s=%s", k, v)) 84 | } 85 | } 86 | 87 | sort.Strings(kvs) 88 | 89 | kvs = append(kvs, fmt.Sprintf("key=%s", wxpay.Config.ApiKey)) 90 | 91 | str := strings.Join(kvs, "&") 92 | 93 | var h hash.Hash 94 | if signType == types.SignTypeHMACSHA256 { 95 | h = hmac.New(sha256.New, []byte(wxpay.Config.ApiKey)) 96 | } else { 97 | h = md5.New() 98 | } 99 | if _, err = h.Write([]byte(str)); err != nil { 100 | return 101 | } 102 | 103 | sign = strings.ToUpper(hex.EncodeToString(h.Sum(nil))) 104 | 105 | if wxpay.Logger != nil { 106 | wxpay.Logger.Printf("Sign %s(%s) = %s", signType, str, sign) 107 | } 108 | 109 | return 110 | } 111 | 112 | /* 113 | SetLogger 日志记录 默认输出到 os.Stdout 114 | 115 | 可以新建 logger 输出到指定文件 116 | 117 | 如果不想开启日志,可以 SetLogger(nil) 118 | */ 119 | func (wxpay *WXPay) SetLogger(logger *log.Logger) { 120 | wxpay.Logger = logger 121 | } 122 | -------------------------------------------------------------------------------- /util/ecb.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Andre Burgaud. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Electronic Code Book (ECB) mode. 6 | 7 | // Implemented for legacy purpose only. ECB should be avoided 8 | // as a mode of operation. Favor other modes available 9 | // in the Go crypto/cipher package (i.e. CBC, GCM, CFB, OFB or CTR). 10 | 11 | // See NIST SP 800-38A, pp 9 12 | 13 | // The source code in this file is a modified copy of 14 | // https://golang.org/src/crypto/cipher/cbc.go 15 | // and released under the following 16 | // Go Authors copyright and license: 17 | 18 | // Copyright 2009 The Go Authors. All rights reserved. 19 | // Use of this source code is governed by a BSD-style 20 | // license that can be found at https://golang.org/LICENSE 21 | 22 | // Package ecb implements block cipher mode of encryption ECB (Electronic Code 23 | // Book) functions. This is implemented for legacy purposes only and should not 24 | // be used for any new encryption needs. Use CBC (Cipher Block Chaining) instead. 25 | package util 26 | 27 | import ( 28 | "crypto/cipher" 29 | ) 30 | 31 | type ecb struct { 32 | b cipher.Block 33 | blockSize int 34 | tmp []byte 35 | } 36 | 37 | func newECB(b cipher.Block) *ecb { 38 | return &ecb{ 39 | b: b, 40 | blockSize: b.BlockSize(), 41 | tmp: make([]byte, b.BlockSize()), 42 | } 43 | } 44 | 45 | type ecbEncrypter ecb 46 | 47 | // NewECBEncrypter returns a BlockMode which encrypts in elecronic codebook (ECB) 48 | // mode, using the given Block (Cipher). 49 | func NewECBEncrypter(b cipher.Block) cipher.BlockMode { 50 | return (*ecbEncrypter)(newECB(b)) 51 | } 52 | 53 | func (x *ecbEncrypter) BlockSize() int { return x.blockSize } 54 | 55 | func (x *ecbEncrypter) CryptBlocks(dst, src []byte) { 56 | 57 | if len(src)%x.blockSize != 0 { 58 | panic("crypto/cipher: input not full blocks") 59 | } 60 | 61 | if len(dst) < len(src) { 62 | panic("crypto/cipher: output smaller than input") 63 | } 64 | 65 | for len(src) > 0 { 66 | x.b.Encrypt(dst[:x.blockSize], src[:x.blockSize]) 67 | src = src[x.blockSize:] 68 | dst = dst[x.blockSize:] 69 | } 70 | } 71 | 72 | type ecbDecrypter ecb 73 | 74 | // NewECBDecrypter returns a BlockMode which decrypts in electronic codebook (ECB) 75 | // mode, using the given Block. 76 | func NewECBDecrypter(b cipher.Block) cipher.BlockMode { 77 | return (*ecbDecrypter)(newECB(b)) 78 | } 79 | 80 | func (x *ecbDecrypter) BlockSize() int { return x.blockSize } 81 | 82 | func (x *ecbDecrypter) CryptBlocks(dst, src []byte) { 83 | if len(src)%x.blockSize != 0 { 84 | panic("crypto/cipher: input not full blocks") 85 | } 86 | if len(dst) < len(src) { 87 | panic("crypto/cipher: output smaller than input") 88 | } 89 | if len(src) == 0 { 90 | return 91 | } 92 | 93 | for len(src) > 0 { 94 | x.b.Decrypt(dst[:x.blockSize], src[:x.blockSize]) 95 | src = src[x.blockSize:] 96 | dst = dst[x.blockSize:] 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /util/string_map_xml_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package util 16 | 17 | import ( 18 | "encoding/xml" 19 | "fmt" 20 | "reflect" 21 | "testing" 22 | ) 23 | 24 | func TestStringMap_MarshalXML(t *testing.T) { 25 | 26 | tests := []struct { 27 | name string 28 | m stringMap 29 | want []byte 30 | }{ 31 | {name: "case1", m: stringMap{ 32 | "key_1": "Value One", 33 | }, want: []byte(`Value One`)}, 34 | } 35 | for _, tt := range tests { 36 | t.Run(tt.name, func(t *testing.T) { 37 | data, _ := xml.Marshal(tt.m) 38 | if !reflect.DeepEqual(data, tt.want) { 39 | t.Errorf("MarshalXML() data = %v, want %v", string(data), string(tt.want)) 40 | return 41 | } 42 | 43 | fmt.Println(string(data)) 44 | }) 45 | } 46 | } 47 | 48 | func TestStringMap_UnmarshalXML(t *testing.T) { 49 | 50 | tests := []struct { 51 | name string 52 | m []byte 53 | want stringMap 54 | }{ 55 | {name: "case1", m: []byte(`Value OneValue Two`), want: stringMap{ 56 | "key_1": "Value One", 57 | "key_2": "Value Two", 58 | }}, 59 | } 60 | for _, tt := range tests { 61 | t.Run(tt.name, func(t *testing.T) { 62 | var data stringMap 63 | _ = xml.Unmarshal(tt.m, &data) 64 | if !reflect.DeepEqual(data, tt.want) { 65 | t.Errorf("MarshalXML() data = %v, want %v", data, tt.want) 66 | return 67 | } 68 | 69 | fmt.Println(data) 70 | }) 71 | } 72 | } 73 | 74 | func TestMap2XML(t *testing.T) { 75 | type args struct { 76 | kvs map[string]string 77 | } 78 | tests := []struct { 79 | name string 80 | args args 81 | wantText []byte 82 | }{ 83 | {name: "case1", args: args{kvs: map[string]string{ 84 | "key_1": "Value One", 85 | }}, wantText: []byte(`Value One`)}, 86 | } 87 | for _, tt := range tests { 88 | t.Run(tt.name, func(t *testing.T) { 89 | gotText, _ := Map2XML(tt.args.kvs) 90 | if !reflect.DeepEqual(gotText, tt.wantText) { 91 | t.Errorf("Map2XML() = %v, want %v", string(gotText), string(tt.wantText)) 92 | } 93 | }) 94 | } 95 | } 96 | 97 | func TestXML2Map(t *testing.T) { 98 | type args struct { 99 | text []byte 100 | } 101 | tests := []struct { 102 | name string 103 | args args 104 | wantResult map[string]string 105 | }{ 106 | {name: "case1", args: args{text: []byte(`Value OneValue Two`)}, wantResult: map[string]string{ 107 | "key_1": "Value One", 108 | "key_2": "Value Two", 109 | }}, 110 | } 111 | for _, tt := range tests { 112 | t.Run(tt.name, func(t *testing.T) { 113 | gotResult, _ := XML2Map(tt.args.text) 114 | if !reflect.DeepEqual(gotResult, tt.wantResult) { 115 | t.Errorf("XML2Map() = %v, want %v", gotResult, tt.wantResult) 116 | } 117 | }) 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /server.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package wxpay 16 | 17 | import ( 18 | "crypto/md5" 19 | "encoding/base64" 20 | "encoding/xml" 21 | "fmt" 22 | "io/ioutil" 23 | "net/http" 24 | 25 | "github.com/fastwego/wxpay/util" 26 | ) 27 | 28 | /* 29 | 响应微信请求 或 推送消息/事件 的服务器 30 | */ 31 | type Server struct { 32 | Ctx *WXPay 33 | } 34 | 35 | /* 36 | 支付结果 回调 37 | 38 | See: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_7&index=3 39 | */ 40 | func (s *Server) PaymentNotify(request *http.Request) (params map[string]string, err error) { 41 | var body []byte 42 | body, err = ioutil.ReadAll(request.Body) 43 | if err != nil { 44 | return 45 | } 46 | 47 | if s.Ctx.Logger != nil { 48 | s.Ctx.Logger.Println("PaymentNotify", string(body)) 49 | } 50 | 51 | params, err = util.XML2Map(body) 52 | if err != nil { 53 | return 54 | } 55 | 56 | // 验证签名 57 | sign, err := s.Ctx.Sign(params, params["sign_type"]) 58 | if err != nil { 59 | return 60 | } 61 | 62 | if params["sign"] != sign { 63 | err = fmt.Errorf(" params.Sign %s != Sign %s", params["sign"], sign) 64 | return 65 | } 66 | 67 | return 68 | } 69 | 70 | /* 71 | 退款结果 回调 72 | 73 | See: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_16&index=11 74 | */ 75 | func (s *Server) RefundNotify(request *http.Request) (params map[string]string, err error) { 76 | var body []byte 77 | body, err = ioutil.ReadAll(request.Body) 78 | if err != nil { 79 | return 80 | } 81 | 82 | if s.Ctx.Logger != nil { 83 | s.Ctx.Logger.Println("RefundNotify", string(body)) 84 | } 85 | 86 | encryptMsg := struct { 87 | XMLName xml.Name `xml:"xml"` 88 | Appid string `xml:"appid"` 89 | Mchid string `xml:"mch_id"` 90 | NonceStr string `xml:"nonce_str"` 91 | ReqInfo string `xml:"req_info"` 92 | }{} 93 | 94 | err = xml.Unmarshal(body, &encryptMsg) 95 | if err != nil { 96 | return 97 | } 98 | 99 | /* 100 | 解密步骤如下: 101 | 102 | (1)对加密串A做 base64解码,得到加密串B 103 | 104 | (2)对商户 key做 md5,得到32位小写 key* ( key设置路径:微信商户平台(pay.weixin.qq.com)-->账户设置-->API安全-->密钥设置 ) 105 | 106 | (3)用 key*对加密串B做AES-256-ECB解密(PKCS7Padding)` 107 | */ 108 | cipherText, err := base64.StdEncoding.DecodeString(encryptMsg.ReqInfo) 109 | if err != nil { 110 | return 111 | } 112 | 113 | key := []byte(fmt.Sprintf("%x", md5.Sum([]byte(s.Ctx.Config.ApiKey)))) 114 | 115 | reqInfo, err := util.AESECBPKCS7Decrypt(cipherText, key) 116 | if err != nil { 117 | return 118 | } 119 | 120 | params, err = util.XML2Map(reqInfo) 121 | if err != nil { 122 | return 123 | } 124 | 125 | return 126 | } 127 | 128 | /* 129 | ResponseSuccess 响应微信消息 130 | 131 | 132 | 133 | 134 | 135 | */ 136 | func (s *Server) ResponseSuccess(writer http.ResponseWriter, request *http.Request) (err error) { 137 | 138 | response := struct { 139 | XMLName xml.Name `xml:"xml"` 140 | ReturnCode util.CDATA `xml:"return_code"` 141 | ReturnMsg util.CDATA `xml:"return_msg"` 142 | }{ 143 | ReturnCode: "SUCCESS", 144 | ReturnMsg: "OK", 145 | } 146 | 147 | output, err := xml.Marshal(response) 148 | if err != nil { 149 | return 150 | } 151 | 152 | _, err = writer.Write(output) 153 | 154 | if s.Ctx.Logger != nil { 155 | s.Ctx.Logger.Println("ResponseSuccess: ", string(output)) 156 | } 157 | 158 | return 159 | } 160 | -------------------------------------------------------------------------------- /client.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package wxpay 16 | 17 | import ( 18 | "bytes" 19 | "crypto/tls" 20 | "encoding/pem" 21 | "encoding/xml" 22 | "errors" 23 | "fmt" 24 | "io/ioutil" 25 | "net/http" 26 | 27 | "github.com/fastwego/wxpay/util" 28 | 29 | "golang.org/x/crypto/pkcs12" 30 | ) 31 | 32 | /* 33 | 微信 api 服务器地址 34 | */ 35 | var WXPayServerUrl = "https://api.mch.weixin.qq.com" 36 | 37 | // 获取RSA公钥API 38 | var RSAServerUrl = "https://fraud.mch.weixin.qq.com" 39 | 40 | /* 41 | HttpClient 用于向接口发送请求 42 | */ 43 | type Client struct { 44 | Ctx *WXPay 45 | } 46 | 47 | //HTTPPost POST 请求 48 | func (client *Client) HTTPPost(uri string, params map[string]string, isCertificate bool) (resp []byte, err error) { 49 | 50 | // 签名 51 | sign, err := client.Ctx.Sign(params, params["sign_type"]) 52 | if err != nil { 53 | return 54 | } 55 | params["sign"] = sign 56 | 57 | body, err := util.Map2XML(params) 58 | if err != nil { 59 | return 60 | } 61 | 62 | // 特殊处理 rsa 接口服务器地址 63 | ServerUrl := WXPayServerUrl 64 | if uri == "/risk/getpublickey" { 65 | ServerUrl = RSAServerUrl 66 | } 67 | 68 | // 是否沙箱 69 | url := ServerUrl + uri 70 | if client.Ctx.Config.IsSandboxMode { 71 | url = ServerUrl + "/sandboxnew" + uri 72 | } 73 | if client.Ctx.Logger != nil { 74 | client.Ctx.Logger.Printf("POST %s %s\n", url, string(body)) 75 | } 76 | 77 | // 是否需要证书 78 | var httpClient *http.Client 79 | if isCertificate && client.Ctx.Config.Cert != "" { 80 | httpClient, err = client.getHttpsClient() 81 | if err != nil { 82 | return 83 | } 84 | } else { 85 | httpClient = http.DefaultClient 86 | } 87 | 88 | response, err := httpClient.Post(url, "application/xml;charset=utf-8", bytes.NewReader(body)) 89 | if err != nil { 90 | return 91 | } 92 | defer response.Body.Close() 93 | return client.responseFilter(response) 94 | } 95 | 96 | // 双向证书 97 | func (client *Client) getHttpsClient() (c *http.Client, err error) { 98 | certfile, err := ioutil.ReadFile(client.Ctx.Config.Cert) 99 | if err != nil { 100 | return 101 | } 102 | 103 | blocks, err := pkcs12.ToPEM(certfile, client.Ctx.Config.Mchid) 104 | if err != nil { 105 | return 106 | } 107 | var pemfile []byte 108 | for _, b := range blocks { 109 | pemfile = append(pemfile, pem.EncodeToMemory(b)...) 110 | } 111 | cert, err := tls.X509KeyPair(pemfile, pemfile) 112 | if err != nil { 113 | return 114 | } 115 | 116 | config := &tls.Config{ 117 | Certificates: []tls.Certificate{cert}, 118 | } 119 | tr := &http.Transport{ 120 | TLSClientConfig: config, 121 | DisableCompression: true, 122 | } 123 | return &http.Client{ 124 | Transport: tr, 125 | }, nil 126 | } 127 | 128 | /* 129 | 筛查微信 api 服务器响应,判断以下错误: 130 | 131 | - http 状态码 不为 200 132 | 133 | - 接口响应错误码 ReturnCode/ResultCode == "FAIL" 134 | */ 135 | func (client *Client) responseFilter(response *http.Response) (resp []byte, err error) { 136 | if response.StatusCode != http.StatusOK { 137 | err = fmt.Errorf("Status %s", response.Status) 138 | return 139 | } 140 | 141 | resp, err = ioutil.ReadAll(response.Body) 142 | if err != nil { 143 | return 144 | } 145 | 146 | if client.Ctx.Logger != nil { 147 | client.Ctx.Logger.Printf("response %s", string(resp)) 148 | } 149 | 150 | // 对于 下载类 接口 不返回 xml 内容 151 | if bytes.HasPrefix(resp, []byte("")) { 152 | errorResponse := struct { 153 | ReturnCode string `xml:"return_code"` 154 | ResultCode string `xml:"result_code"` 155 | }{} 156 | err = xml.Unmarshal(resp, &errorResponse) 157 | if err != nil { 158 | return 159 | } 160 | 161 | if errorResponse.ReturnCode == "FAIL" || errorResponse.ResultCode == "FAIL" { 162 | err = errors.New(string(resp)) 163 | return 164 | } 165 | } 166 | return 167 | } 168 | -------------------------------------------------------------------------------- /server_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 FastWeGo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package wxpay 16 | 17 | import ( 18 | "bytes" 19 | "encoding/xml" 20 | "io/ioutil" 21 | "net/http" 22 | "net/http/httptest" 23 | "reflect" 24 | "testing" 25 | 26 | "github.com/fastwego/wxpay/util" 27 | ) 28 | 29 | func TestServer_PaymentResultNotify(t *testing.T) { 30 | 31 | mockRequest := httptest.NewRequest("POST", "http://example.com/foo", bytes.NewReader([]byte(` 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 1 46 | 47 | 48 | 49 | 50 | 51 | 52 | `))) 53 | 54 | type args struct { 55 | request *http.Request 56 | } 57 | tests := []struct { 58 | name string 59 | args args 60 | wantParams map[string]string 61 | wantErr bool 62 | }{ 63 | {name: "case1", args: args{request: mockRequest}, wantParams: map[string]string{"transaction_id": "1004400740201409030005092168"}, wantErr: false}, 64 | } 65 | for _, tt := range tests { 66 | t.Run(tt.name, func(t *testing.T) { 67 | gotParams, err := MockWXPay.Server.PaymentNotify(tt.args.request) 68 | if (err != nil) != tt.wantErr { 69 | t.Errorf("PaymentNotify() error = %v, wantErr %v", err, tt.wantErr) 70 | return 71 | } 72 | if !reflect.DeepEqual(gotParams["transaction_id"], tt.wantParams["transaction_id"]) { 73 | t.Errorf("PaymentNotify() gotParams = %v, want %v", gotParams, tt.wantParams) 74 | } 75 | }) 76 | } 77 | } 78 | 79 | func TestServer_RefundNotify(t *testing.T) { 80 | 81 | mockRequest := httptest.NewRequest("POST", "http://example.com/foo", bytes.NewReader([]byte(` 82 | SUCCESS 83 | 84 | 85 | 86 | 87 | 88 | `))) 89 | 90 | /* 91 | req_info解密后的示例: 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | */ 108 | 109 | type args struct { 110 | request *http.Request 111 | } 112 | tests := []struct { 113 | name string 114 | args args 115 | wantParams map[string]string 116 | wantErr bool 117 | }{ 118 | {name: "case1", args: args{request: mockRequest}, wantParams: map[string]string{"transaction_id": "4200000215201811190261405420"}, wantErr: false}, 119 | } 120 | for _, tt := range tests { 121 | t.Run(tt.name, func(t *testing.T) { 122 | gotParams, err := MockWXPay.Server.RefundNotify(tt.args.request) 123 | if (err != nil) != tt.wantErr { 124 | t.Errorf("PaymentNotify() error = %v, wantErr %v", err, tt.wantErr) 125 | return 126 | } 127 | if !reflect.DeepEqual(gotParams["transaction_id"], tt.wantParams["transaction_id"]) { 128 | t.Errorf("PaymentNotify() gotParams = %v, want %v", gotParams, tt.wantParams) 129 | } 130 | }) 131 | } 132 | } 133 | 134 | func TestServer_Response(t *testing.T) { 135 | mockRequest := httptest.NewRequest("POST", "http://example.com/foo", nil) 136 | recorder := httptest.NewRecorder() 137 | 138 | type args struct { 139 | writer http.ResponseWriter 140 | request *http.Request 141 | } 142 | tests := []struct { 143 | name string 144 | args args 145 | wantErr bool 146 | }{ 147 | {name: "case1", args: args{writer: recorder, request: mockRequest}, wantErr: false}, 148 | } 149 | for _, tt := range tests { 150 | t.Run(tt.name, func(t *testing.T) { 151 | err := MockWXPay.Server.ResponseSuccess(tt.args.writer, tt.args.request) 152 | if (err != nil) != tt.wantErr { 153 | t.Errorf("ResponseSuccess() error = %v, wantErr %v", err, tt.wantErr) 154 | } 155 | 156 | resp := recorder.Result() 157 | body, _ := ioutil.ReadAll(resp.Body) 158 | 159 | response := struct { 160 | XMLName xml.Name `xml:"xml"` 161 | ReturnCode util.CDATA `xml:"return_code"` 162 | ReturnMsg util.CDATA `xml:"return_msg"` 163 | }{} 164 | 165 | err = xml.Unmarshal(body, &response) 166 | 167 | if response.ReturnCode != "SUCCESS" { 168 | t.Errorf("ResponseSuccess() response.ReturnCode != \"SUCCESS\" but %s", response.ReturnCode) 169 | } 170 | }) 171 | } 172 | } 173 | --------------------------------------------------------------------------------