Skip to content

Commit

Permalink
feat(mini-program): update miniprogram struct and fix build error
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Sep 23, 2021
1 parent c9c5baf commit 0d02781
Show file tree
Hide file tree
Showing 35 changed files with 372 additions and 193 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
root = true

[*]
indent_style = tab
indent_size = tab
2 changes: 2 additions & 0 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on: [ push ]
jobs:
test-go:
runs-on: ubuntu-latest
env:
API_V3_KEY: ${{ secrets.API_V3_KEY }}
steps:
- uses: actions/checkout@v2
- name: Set up Go
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test: test-aes test-message
test: test-aes test-rsa test-signer

test-aes:
# go test -v src/kernel/Encryptor.go src/kernel/Encryptor_test.go
Expand All @@ -7,6 +7,9 @@ test-aes:
test-rsa:
go test -v src/kernel/support/rsa_oaep.go src/kernel/support/rsa_oaep_test.go

test-signer:
go test -v src/kernel/support/signer.go src/kernel/support/signer_test.go

test-message:
go test -v test/featureUnit/main_test.go test/featureUnit/work_message_test.go

Expand All @@ -33,5 +36,5 @@ test-payment:
test-kernel-support:
go test -v src/kernel/support/str.go src/kernel/support/str_test.go

build:payment_order_test.go
build:
go build
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# PowerWechat

[![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)

[![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)
10 changes: 2 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@ module github.com/ArtisanCloud/power-wechat

go 1.16

replace github.com/ArtisanCloud/go-libs => ../go-libs

replace github.com/ArtisanCloud/go-socialite => ../go-socialite

require (
github.com/ArtisanCloud/go-libs v1.1.2
github.com/ArtisanCloud/go-socialite v1.0.7
github.com/ArtisanCloud/go-libs v1.1.3
github.com/ArtisanCloud/go-socialite v1.0.8
github.com/gin-gonic/gin v1.7.2
github.com/go-playground/assert/v2 v2.0.1
github.com/go-playground/validator/v10 v10.6.1 // indirect
github.com/golang-module/carbon v1.4.5
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.1.1
github.com/json-iterator/go v1.1.11 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/stretchr/testify v1.7.0
github.com/ugorji/go v1.2.6 // indirect
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
)
13 changes: 7 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
github.com/ArtisanCloud/go-libs v1.0.19/go.mod h1:4pGEskMX4BA2w2cJdjL4+jcGHRLdx6Bj+evOqXo23iU=
github.com/ArtisanCloud/go-libs v1.1.3 h1:UCvKc80TRl/5MdwMBFM3ymXVwKrZ+gQewyom2xV5DFI=
github.com/ArtisanCloud/go-libs v1.1.3/go.mod h1:4pGEskMX4BA2w2cJdjL4+jcGHRLdx6Bj+evOqXo23iU=
github.com/ArtisanCloud/go-socialite v1.0.8 h1:eugkAA9SvXxltUw5wBZP1RWBva80jAHO4MykWRevCPg=
github.com/ArtisanCloud/go-socialite v1.0.8/go.mod h1:dtDCF49NdzsKEd+nKm6ytv5cVaAfM3O8Hl7fml4K+E4=
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -27,8 +32,6 @@ github.com/go-playground/validator/v10 v10.6.1/go.mod h1:xm76BBt941f7yWdGnI2DVPF
github.com/go-redis/redis/v8 v8.11.0 h1:O1Td0mQ8UFChQ3N9zFQqo6kTU2cJ+/it88gDB+zg0wo=
github.com/go-redis/redis/v8 v8.11.0/go.mod h1:DLomh7y2e3ggQXQLd1YgmvIfecPJoFl7WU5SOQ/r06M=
github.com/golang-module/carbon v1.3.5/go.mod h1:wIIzB2BwewCNV4KyXfAASbAIsCJpwceR9JwVrgqdLIw=
github.com/golang-module/carbon v1.4.5 h1:hpki7tw/s9ehRpwtV1QqdfcV8synrB521ZofwCPyRh8=
github.com/golang-module/carbon v1.4.5/go.mod h1:KfAm8J7tPs877aBRv2KLlIEC2R01zIoh0j7sngyPFG4=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
Expand Down Expand Up @@ -90,12 +93,10 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go v1.2.6 h1:tGiWC9HENWE2tqYycIqFTNorMmFRVhNwCpDOpWqnk8E=
github.com/ugorji/go v1.2.6/go.mod h1:anCg0y61KIhDlPZmnH+so+RQbysYVyDko0IMgJv0Nn0=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/ugorji/go/codec v1.2.6 h1:7kbGefxLoDBuYXOms4yD7223OpNMMPNPZxXk5TvFcyQ=
github.com/ugorji/go/codec v1.2.6/go.mod h1:V6TCNZ4PHqoHGFZuSG1W8nrCzzdgA2DozYxWFFpvxTw=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down
119 changes: 119 additions & 0 deletions src/kernel/models/payment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package models

import "time"

// --- Transaction models ----

// Transaction
type Transaction struct {
Amount *TransactionAmount `json:"amount,omitempty"`
AppID string `json:"appid,omitempty"`
Attach string `json:"attach,omitempty"`
BankType string `json:"bank_type,omitempty"`
MchID string `json:"mchid,omitempty"`
OutTradeNo string `json:"out_trade_no,omitempty"`
Payer *TransactionPayer `json:"payer,omitempty"`
PromotionDetail []PromotionDetail `json:"promotion_detail,omitempty"`
SuccessTime string `json:"success_time,omitempty"`
TradeState string `json:"trade_state,omitempty"`
TradeStateDesc string `json:"trade_state_desc,omitempty"`
TradeType string `json:"trade_type,omitempty"`
TransactionId string `json:"transaction_id,omitempty"`
}


// TransactionAmount
type TransactionAmount struct {
Currency string `json:"currency,omitempty"`
PayerCurrency string `json:"payer_currency,omitempty"`
PayerTotal int64 `json:"payer_total,omitempty"`
Total int64 `json:"total,omitempty"`
}


// TransactionPayer
type TransactionPayer struct {
Openid string `json:"openid,omitempty"`
}


// PromotionDetail
type PromotionDetail struct {
// 券ID
CouponId string `json:"coupon_id,omitempty"`
// 优惠名称
Name string `json:"name,omitempty"`
// GLOBAL:全场代金券;SINGLE:单品优惠
Scope string `json:"scope,omitempty"`
// CASH:充值;NOCASH:预充值。
Type string `json:"type,omitempty"`
// 优惠券面额
Amount int64 `json:"amount,omitempty"`
// 活动ID,批次ID
StockId string `json:"stock_id,omitempty"`
// 单位为分
WechatpayContribute int64 `json:"wechatpay_contribute,omitempty"`
// 单位为分
MerchantContribute int64 `json:"merchant_contribute,omitempty"`
// 单位为分
OtherContribute int64 `json:"other_contribute,omitempty"`
// CNY:人民币,境内商户号仅支持人民币。
Currency string `json:"currency,omitempty"`
GoodsDetail []PromotionGoodsDetail `json:"goods_detail,omitempty"`
}


// PromotionGoodsDetail
type PromotionGoodsDetail struct {
// 商品编码
GoodsId string `json:"goods_id"`
// 商品数量
Quantity int64 `json:"quantity"`
// 商品价格
UnitPrice int64 `json:"unit_price"`
// 商品优惠金额
DiscountAmount int64 `json:"discount_amount"`
// 商品备注
GoodsRemark string `json:"goods_remark,omitempty"`
}



// --- Refund models ----
// Refund
type Refund struct {
// 原支付交易对应的商户订单号
MchID string `json:"mchid"`
// 微信支付交易订单号
TransactionId string `json:"transaction_id"`
// 原支付交易对应的商户订单号
OutTradeNo string `json:"out_trade_no"`
// 微信支付退款号
RefundId string `json:"refund_id"`
// 商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。
OutRefundNo string `json:"out_refund_no"`
// 退款状态,枚举值
RefundStatus string `json:"refund_status"`
// 退款成功时间,退款状态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秒。
SuccessTime *time.Time `json:"success_time,omitempty"`
// 取当前退款单的退款入账方,有以下几种情况: 1)退回银行卡:{银行名称}{卡类型}{卡尾号} 2)退回支付用户零钱:支付用户零钱 3)退还商户:商户基本账户商户结算银行账户 4)退回支付用户零钱通:支付用户零钱通
UserReceivedAccount string `json:"user_received_account"`
// 金额详细信息
Amount *Amount `json:"amount"`

}


// Amount
type Amount struct {
// 订单总金额,单位为分
Total int64 `json:"total"`
// 退款标价金额,单位为分,可以做部分退款
Refund int64 `json:"refund"`
// 现金支付金额,单位为分,只能为整数
PayerTotal int64 `json:"payer_total"`
// 退款给用户的金额,不包含所有优惠券金额
PayerRefund int64 `json:"payer_refund"`
// 去掉非充值代金券退款金额后的退款金额,单位为分,退款金额=申请退款金额-非充值代金券退款金额,退款金额<=申请退款金额

}
46 changes: 15 additions & 31 deletions src/kernel/response/wx.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,35 @@
package response

type ResponseWork struct {
ErrCode int `json:"errcode"`
ErrMSG string `json:"errmsg"`
ErrCode int `json:"errcode,omitempty"`
ErrMSG string `json:"errmsg,omitempty"`
}

type ResponsePayment struct {
ReturnCode string `json:"return_code"`
ReturnMSG string `json:"return_msg"`
ReturnCode string `json:"return_code,omitempty"`
ReturnMSG string `json:"return_msg,omitempty"`

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

type ResponseMiniProgram struct {
Msg string `json:"msg,omitempty"` // 小程序直播的部分接口会把错误提示抛在msg字段
ErrCode int `json:"errcode"`
ErrMSG string `json:"errmsg"`

ResultCode string `json:"resultcode"`
ResultMSG string `json:"resultmsg"`

}

type ResponseOfficialAccount struct {
ErrCode int `json:"errcode"`
ErrMSG string `json:"errmsg"`

ResultCode string `json:"resultcode"`
ResultMSG string `json:"resultmsg"`
}

type ResponseOfficialAccount struct {
ErrCode int `json:"errcode"`
ErrMSG string `json:"errmsg"`
ErrMSG string `json:"errmsg,omitempty"`

ResultCode string `json:"resultcode"`
ResultMSG string `json:"resultmsg"`
ResultCode string `json:"resultcode,omitempty"`
ResultMSG string `json:"resultmsg,omitempty"`
}

type ResponseOfficialAccount struct {
ErrCode int `json:"errcode"`
ErrMSG string `json:"errmsg"`
ErrMSG string `json:"errmsg,omitempty"`

ResultCode string `json:"resultcode"`
ResultMSG string `json:"resultmsg"`
ResultCode string `json:"resultcode,omitempty"`
ResultMSG string `json:"resultmsg,omitempty"`
}

//
Expand Down
2 changes: 1 addition & 1 deletion src/miniProgram/dataCube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/ArtisanCloud/go-libs/object"
"github.com/ArtisanCloud/power-wechat/src/kernel"
"github.com/ArtisanCloud/power-wechat/src/kernel/power"
"github.com/ArtisanCloud/power-wechat/src/miniprogram/dataCube/response"
"github.com/ArtisanCloud/power-wechat/src/miniProgram/dataCube/response"
)

type Client struct {
Expand Down
4 changes: 2 additions & 2 deletions src/miniProgram/liveBroadcast/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (comp *Client) GoodsSale(roomID int, goodsID int, onSale int) (*response2.R
return result, err
}

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

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

options := &object.HashMap{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package request

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

type RequestBroadcastAddAssistant struct {
RoomID int `json:"roomId"`
Users []power.StringMap `json:"users"`
RoomID int `json:"roomId"`
Users []RequestBroadcastAddAssistantUser `json:"users"`
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package request

type RequestBroadcastAddGoods struct {
IDs string `json:"ids"`
RoomID int `json:"roomId"`
IDs []int `json:"ids"`
RoomID int `json:"roomId"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ type RequestBroadcastGetRoleList struct {
Role int `json:"role"`
Offset int `json:"offset"`
Limit int `json:"limit"`
Keyword string `json:"keyword"`
Keyword string `json:"keyword,omitempty"`
}
14 changes: 11 additions & 3 deletions src/miniProgram/liveBroadcast/request/requestBroadcastGoodsAdd.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package request

import "github.com/ArtisanCloud/power-wechat/src/kernel/power"

type RequestBroadcastGoodsAdd struct {
GoodsInfo *power.HashMap `json:"goodsInfo"`
GoodsInfo *RequestBroadcastGoodsAddInfo `json:"goodsInfo"`
}

type RequestBroadcastGoodsAddInfo struct {
CoverImgUrl string `json:"coverImgUrl"`
Name string `json:"name"`
PriceType int `json:"priceType"`
Price float64 `json:"price"`
Price2 float64 `json:"price2"`
Url string `json:"url"`
ThirdPartyAppid string `json:"thirdPartyAppid"` // 当商品为第三方小程序的商品则填写为对应第三方小程序的appid,自身小程序商品则为''
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package request

type RequestBroadcastGoodsSort struct {
GoodsId string `json:"goodsId"`
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package request

import "github.com/ArtisanCloud/power-wechat/src/kernel/power"

type RequestBroadcastGoodsUpdate struct {
GoodsInfo *power.HashMap `json:"goodsInfo"`
GoodsInfo *RequestBroadcastGoodsUpdateInfo `json:"goodsInfo"`
}

type RequestBroadcastGoodsUpdateInfo struct {
GoodsId int `json:"goodsId"`
CoverImgUrl string `json:"coverImgUrl,omitempty"`
Name string `json:"name,omitempty"`
PriceType int `json:"priceType,omitempty'"`
Price float64 `json:"price,omitempty"`
Price2 float64 `json:"price2,omitempty"`
Url string `json:"url,omitempty"`
ThirdPartyAppid string `json:"thirdPartyAppid,omitempty"` // 当商品为第三方小程序的商品则填写为对应第三方小程序的appid,自身小程序商品则为''
}
Loading

0 comments on commit 0d02781

Please sign in to comment.