Skip to content

Commit 0d02781

Browse files
WalleVMatrix-XWalle
authored
feat(mini-program): update miniprogram struct and fix build error
* update * update * update strong var statement * update * update * update * fix(officialAccount) - namespace * update * feat(mini-program): update miniprogram struct * fix(go.mod): update go-libs and go-socalite * fix(makefile): update makefile test scope * fix(base): fix import case error Co-authored-by: Matrix-X <matrix-x@artisan-cloud.com> Co-authored-by: Walle <walle@artisan-cloud.com>
1 parent c9c5baf commit 0d02781

35 files changed

+372
-193
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
indent_size = tab

.github/workflows/go-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on: [ push ]
44
jobs:
55
test-go:
66
runs-on: ubuntu-latest
7+
env:
8+
API_V3_KEY: ${{ secrets.API_V3_KEY }}
79
steps:
810
- uses: actions/checkout@v2
911
- name: Set up Go

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
test: test-aes test-message
1+
test: test-aes test-rsa test-signer
22

33
test-aes:
44
# go test -v src/kernel/Encryptor.go src/kernel/Encryptor_test.go
@@ -7,6 +7,9 @@ test-aes:
77
test-rsa:
88
go test -v src/kernel/support/rsa_oaep.go src/kernel/support/rsa_oaep_test.go
99

10+
test-signer:
11+
go test -v src/kernel/support/signer.go src/kernel/support/signer_test.go
12+
1013
test-message:
1114
go test -v test/featureUnit/main_test.go test/featureUnit/work_message_test.go
1215

@@ -33,5 +36,5 @@ test-payment:
3336
test-kernel-support:
3437
go test -v src/kernel/support/str.go src/kernel/support/str_test.go
3538

36-
build:payment_order_test.go
39+
build:
3740
go build

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# PowerWechat
2+
3+
[![Go Build](https://github.com/ArtisanCloud/power-wechat/actions/workflows/go-build.yml/badge.svg?branch=release%2F1.0.0)](https://github.com/ArtisanCloud/power-wechat/actions/workflows/go-build.yml)
4+
5+
[![Go Test](https://github.com/ArtisanCloud/power-wechat/actions/workflows/go-test.yml/badge.svg?branch=release%2F1.0.0)](https://github.com/ArtisanCloud/power-wechat/actions/workflows/go-test.yml)

go.mod

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,18 @@ module github.com/ArtisanCloud/power-wechat
22

33
go 1.16
44

5-
replace github.com/ArtisanCloud/go-libs => ../go-libs
6-
7-
replace github.com/ArtisanCloud/go-socialite => ../go-socialite
8-
95
require (
10-
github.com/ArtisanCloud/go-libs v1.1.2
11-
github.com/ArtisanCloud/go-socialite v1.0.7
6+
github.com/ArtisanCloud/go-libs v1.1.3
7+
github.com/ArtisanCloud/go-socialite v1.0.8
128
github.com/gin-gonic/gin v1.7.2
139
github.com/go-playground/assert/v2 v2.0.1
1410
github.com/go-playground/validator/v10 v10.6.1 // indirect
15-
github.com/golang-module/carbon v1.4.5
1611
github.com/golang/protobuf v1.5.2 // indirect
1712
github.com/google/uuid v1.1.1
1813
github.com/json-iterator/go v1.1.11 // indirect
1914
github.com/leodido/go-urn v1.2.1 // indirect
2015
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
2116
github.com/modern-go/reflect2 v1.0.1 // indirect
2217
github.com/stretchr/testify v1.7.0
23-
github.com/ugorji/go v1.2.6 // indirect
2418
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
2519
)

go.sum

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
github.com/ArtisanCloud/go-libs v1.0.19/go.mod h1:4pGEskMX4BA2w2cJdjL4+jcGHRLdx6Bj+evOqXo23iU=
2+
github.com/ArtisanCloud/go-libs v1.1.3 h1:UCvKc80TRl/5MdwMBFM3ymXVwKrZ+gQewyom2xV5DFI=
3+
github.com/ArtisanCloud/go-libs v1.1.3/go.mod h1:4pGEskMX4BA2w2cJdjL4+jcGHRLdx6Bj+evOqXo23iU=
4+
github.com/ArtisanCloud/go-socialite v1.0.8 h1:eugkAA9SvXxltUw5wBZP1RWBva80jAHO4MykWRevCPg=
5+
github.com/ArtisanCloud/go-socialite v1.0.8/go.mod h1:dtDCF49NdzsKEd+nKm6ytv5cVaAfM3O8Hl7fml4K+E4=
16
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
27
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
38
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -27,8 +32,6 @@ github.com/go-playground/validator/v10 v10.6.1/go.mod h1:xm76BBt941f7yWdGnI2DVPF
2732
github.com/go-redis/redis/v8 v8.11.0 h1:O1Td0mQ8UFChQ3N9zFQqo6kTU2cJ+/it88gDB+zg0wo=
2833
github.com/go-redis/redis/v8 v8.11.0/go.mod h1:DLomh7y2e3ggQXQLd1YgmvIfecPJoFl7WU5SOQ/r06M=
2934
github.com/golang-module/carbon v1.3.5/go.mod h1:wIIzB2BwewCNV4KyXfAASbAIsCJpwceR9JwVrgqdLIw=
30-
github.com/golang-module/carbon v1.4.5 h1:hpki7tw/s9ehRpwtV1QqdfcV8synrB521ZofwCPyRh8=
31-
github.com/golang-module/carbon v1.4.5/go.mod h1:KfAm8J7tPs877aBRv2KLlIEC2R01zIoh0j7sngyPFG4=
3235
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
3336
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
3437
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
@@ -90,12 +93,10 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
9093
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
9194
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
9295
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
96+
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
9397
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
94-
github.com/ugorji/go v1.2.6 h1:tGiWC9HENWE2tqYycIqFTNorMmFRVhNwCpDOpWqnk8E=
95-
github.com/ugorji/go v1.2.6/go.mod h1:anCg0y61KIhDlPZmnH+so+RQbysYVyDko0IMgJv0Nn0=
98+
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
9699
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
97-
github.com/ugorji/go/codec v1.2.6 h1:7kbGefxLoDBuYXOms4yD7223OpNMMPNPZxXk5TvFcyQ=
98-
github.com/ugorji/go/codec v1.2.6/go.mod h1:V6TCNZ4PHqoHGFZuSG1W8nrCzzdgA2DozYxWFFpvxTw=
99100
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
100101
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
101102
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=

src/kernel/models/payment.go

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package models
2+
3+
import "time"
4+
5+
// --- Transaction models ----
6+
7+
// Transaction
8+
type Transaction struct {
9+
Amount *TransactionAmount `json:"amount,omitempty"`
10+
AppID string `json:"appid,omitempty"`
11+
Attach string `json:"attach,omitempty"`
12+
BankType string `json:"bank_type,omitempty"`
13+
MchID string `json:"mchid,omitempty"`
14+
OutTradeNo string `json:"out_trade_no,omitempty"`
15+
Payer *TransactionPayer `json:"payer,omitempty"`
16+
PromotionDetail []PromotionDetail `json:"promotion_detail,omitempty"`
17+
SuccessTime string `json:"success_time,omitempty"`
18+
TradeState string `json:"trade_state,omitempty"`
19+
TradeStateDesc string `json:"trade_state_desc,omitempty"`
20+
TradeType string `json:"trade_type,omitempty"`
21+
TransactionId string `json:"transaction_id,omitempty"`
22+
}
23+
24+
25+
// TransactionAmount
26+
type TransactionAmount struct {
27+
Currency string `json:"currency,omitempty"`
28+
PayerCurrency string `json:"payer_currency,omitempty"`
29+
PayerTotal int64 `json:"payer_total,omitempty"`
30+
Total int64 `json:"total,omitempty"`
31+
}
32+
33+
34+
// TransactionPayer
35+
type TransactionPayer struct {
36+
Openid string `json:"openid,omitempty"`
37+
}
38+
39+
40+
// PromotionDetail
41+
type PromotionDetail struct {
42+
// 券ID
43+
CouponId string `json:"coupon_id,omitempty"`
44+
// 优惠名称
45+
Name string `json:"name,omitempty"`
46+
// GLOBAL:全场代金券;SINGLE:单品优惠
47+
Scope string `json:"scope,omitempty"`
48+
// CASH:充值;NOCASH:预充值。
49+
Type string `json:"type,omitempty"`
50+
// 优惠券面额
51+
Amount int64 `json:"amount,omitempty"`
52+
// 活动ID,批次ID
53+
StockId string `json:"stock_id,omitempty"`
54+
// 单位为分
55+
WechatpayContribute int64 `json:"wechatpay_contribute,omitempty"`
56+
// 单位为分
57+
MerchantContribute int64 `json:"merchant_contribute,omitempty"`
58+
// 单位为分
59+
OtherContribute int64 `json:"other_contribute,omitempty"`
60+
// CNY:人民币,境内商户号仅支持人民币。
61+
Currency string `json:"currency,omitempty"`
62+
GoodsDetail []PromotionGoodsDetail `json:"goods_detail,omitempty"`
63+
}
64+
65+
66+
// PromotionGoodsDetail
67+
type PromotionGoodsDetail struct {
68+
// 商品编码
69+
GoodsId string `json:"goods_id"`
70+
// 商品数量
71+
Quantity int64 `json:"quantity"`
72+
// 商品价格
73+
UnitPrice int64 `json:"unit_price"`
74+
// 商品优惠金额
75+
DiscountAmount int64 `json:"discount_amount"`
76+
// 商品备注
77+
GoodsRemark string `json:"goods_remark,omitempty"`
78+
}
79+
80+
81+
82+
// --- Refund models ----
83+
// Refund
84+
type Refund struct {
85+
// 原支付交易对应的商户订单号
86+
MchID string `json:"mchid"`
87+
// 微信支付交易订单号
88+
TransactionId string `json:"transaction_id"`
89+
// 原支付交易对应的商户订单号
90+
OutTradeNo string `json:"out_trade_no"`
91+
// 微信支付退款号
92+
RefundId string `json:"refund_id"`
93+
// 商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。
94+
OutRefundNo string `json:"out_refund_no"`
95+
// 退款状态,枚举值
96+
RefundStatus string `json:"refund_status"`
97+
// 退款成功时间,退款状态status为SUCCESS(退款成功)时,返回该字段。遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss+TIMEZONE,YYYY-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日13点29分35秒。
98+
SuccessTime *time.Time `json:"success_time,omitempty"`
99+
// 取当前退款单的退款入账方,有以下几种情况: 1)退回银行卡:{银行名称}{卡类型}{卡尾号} 2)退回支付用户零钱:支付用户零钱 3)退还商户:商户基本账户商户结算银行账户 4)退回支付用户零钱通:支付用户零钱通
100+
UserReceivedAccount string `json:"user_received_account"`
101+
// 金额详细信息
102+
Amount *Amount `json:"amount"`
103+
104+
}
105+
106+
107+
// Amount
108+
type Amount struct {
109+
// 订单总金额,单位为分
110+
Total int64 `json:"total"`
111+
// 退款标价金额,单位为分,可以做部分退款
112+
Refund int64 `json:"refund"`
113+
// 现金支付金额,单位为分,只能为整数
114+
PayerTotal int64 `json:"payer_total"`
115+
// 退款给用户的金额,不包含所有优惠券金额
116+
PayerRefund int64 `json:"payer_refund"`
117+
// 去掉非充值代金券退款金额后的退款金额,单位为分,退款金额=申请退款金额-非充值代金券退款金额,退款金额<=申请退款金额
118+
119+
}

src/kernel/response/wx.go

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,35 @@
11
package response
22

33
type ResponseWork struct {
4-
ErrCode int `json:"errcode"`
5-
ErrMSG string `json:"errmsg"`
4+
ErrCode int `json:"errcode,omitempty"`
5+
ErrMSG string `json:"errmsg,omitempty"`
66
}
77

88
type ResponsePayment struct {
9-
ReturnCode string `json:"return_code"`
10-
ReturnMSG string `json:"return_msg"`
9+
ReturnCode string `json:"return_code,omitempty"`
10+
ReturnMSG string `json:"return_msg,omitempty"`
1111

12-
ResultCode string `json:"result_code"` // 是 String(16) SUCCESS/FAIL
13-
ErrCode string `json:"err_code"` // 否 String(32) SYSTEMERROR--系统错误
14-
ErrMSG string `json:"errmsg"`
15-
ErrCodeDes string `json:"err_code_des"`
12+
ResultCode string `json:"result_code,omitempty"` // 是 String(16) SUCCESS/FAIL
13+
ErrCode string `json:"err_code,omitempty"` // 否 String(32) SYSTEMERROR--系统错误
14+
ErrMSG string `json:"errmsg,omitempty"`
15+
ErrCodeDes string `json:"err_code_des,omitempty"`
1616
}
1717

1818
type ResponseMiniProgram struct {
19+
Msg string `json:"msg,omitempty"` // 小程序直播的部分接口会把错误提示抛在msg字段
1920
ErrCode int `json:"errcode"`
20-
ErrMSG string `json:"errmsg"`
21-
22-
ResultCode string `json:"resultcode"`
23-
ResultMSG string `json:"resultmsg"`
24-
25-
}
26-
27-
type ResponseOfficialAccount struct {
28-
ErrCode int `json:"errcode"`
29-
ErrMSG string `json:"errmsg"`
30-
31-
ResultCode string `json:"resultcode"`
32-
ResultMSG string `json:"resultmsg"`
33-
}
34-
35-
type ResponseOfficialAccount struct {
36-
ErrCode int `json:"errcode"`
37-
ErrMSG string `json:"errmsg"`
21+
ErrMSG string `json:"errmsg,omitempty"`
3822

39-
ResultCode string `json:"resultcode"`
40-
ResultMSG string `json:"resultmsg"`
23+
ResultCode string `json:"resultcode,omitempty"`
24+
ResultMSG string `json:"resultmsg,omitempty"`
4125
}
4226

4327
type ResponseOfficialAccount struct {
4428
ErrCode int `json:"errcode"`
45-
ErrMSG string `json:"errmsg"`
29+
ErrMSG string `json:"errmsg,omitempty"`
4630

47-
ResultCode string `json:"resultcode"`
48-
ResultMSG string `json:"resultmsg"`
31+
ResultCode string `json:"resultcode,omitempty"`
32+
ResultMSG string `json:"resultmsg,omitempty"`
4933
}
5034

5135
//

src/miniProgram/dataCube/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"github.com/ArtisanCloud/go-libs/object"
55
"github.com/ArtisanCloud/power-wechat/src/kernel"
66
"github.com/ArtisanCloud/power-wechat/src/kernel/power"
7-
"github.com/ArtisanCloud/power-wechat/src/miniprogram/dataCube/response"
7+
"github.com/ArtisanCloud/power-wechat/src/miniProgram/dataCube/response"
88
)
99

1010
type Client struct {

src/miniProgram/liveBroadcast/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func (comp *Client) GoodsSale(roomID int, goodsID int, onSale int) (*response2.R
285285
return result, err
286286
}
287287

288-
// 重新提交审核
288+
// 删除直播间商品
289289
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/livebroadcast/liveBroadcast.goodsAudit.html
290290
func (comp *Client) GoodsDeleteInRoom(roomID int, goodsID int) (*response2.ResponseMiniProgram, error) {
291291
result := &response2.ResponseMiniProgram{}
@@ -317,7 +317,7 @@ func (comp *Client) GoodsPush(roomID int, goodsID int) (*response2.ResponseMiniP
317317

318318
// 直播间商品排序
319319
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/livebroadcast/liveBroadcast.goodsSort.html
320-
func (comp *Client) GoodsSort(roomID int, goods *power.HashMap) (*response2.ResponseMiniProgram, error) {
320+
func (comp *Client) GoodsSort(roomID int, goods []request.RequestBroadcastGoodsSort) (*response2.ResponseMiniProgram, error) {
321321
result := &response2.ResponseMiniProgram{}
322322

323323
options := &object.HashMap{
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package request
22

3-
import "github.com/ArtisanCloud/power-wechat/src/kernel/power"
3+
type RequestBroadcastAddAssistantUser struct {
4+
Username string `json:"username"`
5+
Nickname string `json:"nickname"`
6+
}
47

58
type RequestBroadcastAddAssistant struct {
6-
RoomID int `json:"roomId"`
7-
Users []power.StringMap `json:"users"`
9+
RoomID int `json:"roomId"`
10+
Users []RequestBroadcastAddAssistantUser `json:"users"`
811
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package request
22

33
type RequestBroadcastAddGoods struct {
4-
IDs string `json:"ids"`
5-
RoomID int `json:"roomId"`
4+
IDs []int `json:"ids"`
5+
RoomID int `json:"roomId"`
66
}

src/miniProgram/liveBroadcast/request/requestBroadcastGetRoleList.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ type RequestBroadcastGetRoleList struct {
44
Role int `json:"role"`
55
Offset int `json:"offset"`
66
Limit int `json:"limit"`
7-
Keyword string `json:"keyword"`
7+
Keyword string `json:"keyword,omitempty"`
88
}
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package request
22

3-
import "github.com/ArtisanCloud/power-wechat/src/kernel/power"
4-
53
type RequestBroadcastGoodsAdd struct {
6-
GoodsInfo *power.HashMap `json:"goodsInfo"`
4+
GoodsInfo *RequestBroadcastGoodsAddInfo `json:"goodsInfo"`
5+
}
6+
7+
type RequestBroadcastGoodsAddInfo struct {
8+
CoverImgUrl string `json:"coverImgUrl"`
9+
Name string `json:"name"`
10+
PriceType int `json:"priceType"`
11+
Price float64 `json:"price"`
12+
Price2 float64 `json:"price2"`
13+
Url string `json:"url"`
14+
ThirdPartyAppid string `json:"thirdPartyAppid"` // 当商品为第三方小程序的商品则填写为对应第三方小程序的appid,自身小程序商品则为''
715
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package request
2+
3+
type RequestBroadcastGoodsSort struct {
4+
GoodsId string `json:"goodsId"`
5+
}
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
package request
22

3-
import "github.com/ArtisanCloud/power-wechat/src/kernel/power"
4-
53
type RequestBroadcastGoodsUpdate struct {
6-
GoodsInfo *power.HashMap `json:"goodsInfo"`
4+
GoodsInfo *RequestBroadcastGoodsUpdateInfo `json:"goodsInfo"`
5+
}
6+
7+
type RequestBroadcastGoodsUpdateInfo struct {
8+
GoodsId int `json:"goodsId"`
9+
CoverImgUrl string `json:"coverImgUrl,omitempty"`
10+
Name string `json:"name,omitempty"`
11+
PriceType int `json:"priceType,omitempty'"`
12+
Price float64 `json:"price,omitempty"`
13+
Price2 float64 `json:"price2,omitempty"`
14+
Url string `json:"url,omitempty"`
15+
ThirdPartyAppid string `json:"thirdPartyAppid,omitempty"` // 当商品为第三方小程序的商品则填写为对应第三方小程序的appid,自身小程序商品则为''
716
}

0 commit comments

Comments
 (0)