Skip to content

Commit 06c1a97

Browse files
committed
小程序url_link
1 parent 2a295bc commit 06c1a97

File tree

8 files changed

+96
-27
lines changed

8 files changed

+96
-27
lines changed

miniprogram/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
## 包说明
66

7-
- analysis 数据分析相关 API
7+
- analysis 数据分析相关 API
8+
- auth 授权
9+
- url 小程序url link
10+
- qrcode 小程序二维码
811

912
## 快速入门
1013

miniprogram/miniprogram.go

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/fideism/golang-wechat/miniprogram/qrcode"
1111
"github.com/fideism/golang-wechat/miniprogram/subscribe"
1212
"github.com/fideism/golang-wechat/miniprogram/tcb"
13+
"github.com/fideism/golang-wechat/miniprogram/url"
1314
)
1415

1516
//MiniProgram 微信小程序相关API
@@ -66,3 +67,8 @@ func (miniProgram *MiniProgram) GetTcb() *tcb.Tcb {
6667
func (miniProgram *MiniProgram) GetSubscribe() *subscribe.Subscribe {
6768
return subscribe.NewSubscribe(miniProgram.ctx)
6869
}
70+
71+
//GetURL 小程序链接
72+
func (miniProgram *MiniProgram) GetURL() *url.URL {
73+
return url.NewURL(miniProgram.ctx)
74+
}

miniprogram/url/link.go

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package url
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/fideism/golang-wechat/miniprogram/context"
7+
"github.com/fideism/golang-wechat/util"
8+
)
9+
10+
// 文档地址 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-link/urllink.generate.html
11+
12+
//generateURLLink url_link.generate
13+
const generateURLLink = `https://api.weixin.qq.com/wxa/generate_urllink?access_token=%s`
14+
15+
// URL struct
16+
type URL struct {
17+
*context.Context
18+
}
19+
20+
// NewURL 实例
21+
func NewURL(ctx *context.Context) *URL {
22+
return &URL{ctx}
23+
}
24+
25+
// GenerateRequest 请求
26+
type GenerateRequest struct {
27+
EnvVersion string `json:"env_version"`
28+
Path string `json:"path"`
29+
Query string `json:"query"`
30+
IsExpire bool `json:"is_expire"`
31+
ExpireType int8 `json:"expire_type"`
32+
ExpireInterval int8 `json:"expire_interval"`
33+
}
34+
35+
// GenerateResponse 响应
36+
type GenerateResponse struct {
37+
util.CommonError
38+
URLLink string `json:"url_link"`
39+
}
40+
41+
// Generate 生成URL Link
42+
func (u *URL) Generate(req GenerateRequest) (*GenerateResponse, error) {
43+
accessToken, tokenErr := u.GetAccessToken()
44+
fmt.Println(accessToken)
45+
if tokenErr != nil {
46+
return nil, tokenErr
47+
}
48+
uri := fmt.Sprintf(generateURLLink, accessToken)
49+
response, err := util.PostJSON(uri, req)
50+
if err != nil {
51+
return nil, err
52+
}
53+
54+
var result GenerateResponse
55+
err = util.DecodeWithError(response, &result, "Generate")
56+
57+
return &result, nil
58+
}

officialaccount/card/card.go

+16-15
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@ package card
22

33
import (
44
"fmt"
5+
"strings"
6+
57
"github.com/fideism/golang-wechat/officialaccount/context"
68
"github.com/fideism/golang-wechat/util"
7-
"strings"
89
)
910

10-
// Type 券类型
11-
type Type string
11+
// CouponType 券类型
12+
type CouponType string
1213

1314
const (
1415
// Groupon 团购券类型
15-
Groupon Type = "GROUPON"
16+
Groupon CouponType = "GROUPON"
1617
// Cash 代金券类型
17-
Cash Type = "CASH"
18+
Cash CouponType = "CASH"
1819
// Discount 折扣券类型
19-
Discount Type = "DISCOUNT"
20+
Discount CouponType = "DISCOUNT"
2021
// Gift 兑换券类型
21-
Gift Type = "GIFT"
22+
Gift CouponType = "GIFT"
2223
// GeneralCoupon 通用券。
23-
GeneralCoupon Type = "GENERAL_COUPON"
24+
GeneralCoupon CouponType = "GENERAL_COUPON"
2425
// MemberCard 会员卡
25-
MemberCard Type = "MEMBER_CARD"
26+
MemberCard CouponType = "MEMBER_CARD"
2627
// GeneralCard 礼品卡
27-
GeneralCard Type = "GENERAL_CARD"
28+
GeneralCard CouponType = "GENERAL_CARD"
2829
)
2930

3031
// Status 卡券状态
@@ -57,7 +58,7 @@ func NewCard(context *context.Context) *Card {
5758
}
5859

5960
// CreateCard 创建卡券
60-
func (card *Card) CreateCard(t Type, attrs util.Params) (cardID string, err error) {
61+
func (card *Card) CreateCard(t CouponType, attrs util.Params) (cardID string, err error) {
6162
var token string
6263
token, err = card.GetAccessToken()
6364
if err != nil {
@@ -94,7 +95,7 @@ func (card *Card) CreateCard(t Type, attrs util.Params) (cardID string, err erro
9495
}
9596

9697
// UpdateCard 修改卡券信息
97-
func (card *Card) UpdateCard(cardID string, t Type, attrs util.Params) (check bool, err error) {
98+
func (card *Card) UpdateCard(cardID string, t CouponType, attrs util.Params) (check bool, err error) {
9899
var token string
99100
token, err = card.GetAccessToken()
100101
if err != nil {
@@ -270,14 +271,14 @@ func (card *Card) CreateCardQrcode(attr util.Params) (res Qrcode, err error) {
270271
return
271272
}
272273

273-
// GetHtml 图文消息群发卡券
274-
func (card *Card) GetHtml(cardID string) (content string, err error) {
274+
// GetHTML 图文消息群发卡券
275+
func (card *Card) GetHTML(cardID string) (content string, err error) {
275276
var token string
276277
token, err = card.GetAccessToken()
277278
if err != nil {
278279
return
279280
}
280-
url := fmt.Sprintf(getHtmlURL, token)
281+
url := fmt.Sprintf(getHTMLURL, token)
281282

282283
var response []byte
283284
response, err = util.PostJSON(url, map[string]interface{}{

officialaccount/card/urls.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const (
99
updateURL = "https://api.weixin.qq.com/card/update?access_token=%s"
1010
deleteURL = "https://api.weixin.qq.com/card/delete?access_token=%s"
1111
createQrcodeURL = "https://api.weixin.qq.com/card/qrcode/create?access_token=%s"
12-
getHtmlURL = "https://api.weixin.qq.com/card/mpnews/gethtml?access_token=%s"
12+
getHTMLURL = "https://api.weixin.qq.com/card/mpnews/gethtml?access_token=%s"
1313
whitelistURL = "https://api.weixin.qq.com/card/testwhitelist/set?access_token=%s"
1414

1515
memberSetActivateFieldURL = "https://api.weixin.qq.com/card/membercard/activateuserform/set"

officialaccount/message/template.go

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type TemplateDataItem struct {
4545
Color string `json:"color,omitempty"`
4646
}
4747

48+
// TemplateSendResult ...
4849
type TemplateSendResult struct {
4950
util.CommonError
5051

pay/notify/notify.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ type RefundNotifyXML struct {
8282
ReturnMsg string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
8383
Appid string `xml:"appid,omitempty" json:"appid,omitempty"`
8484
SubAppid string `xml:"sub_appid,omitempty" json:"sub_appid,omitempty"`
85-
MchId string `xml:"mch_id,omitempty" json:"mch_id,omitempty"`
86-
SubMchId string `xml:"sub_mch_id,omitempty" json:"sub_mch_id,omitempty"`
85+
MchID string `xml:"mch_id,omitempty" json:"mch_id,omitempty"`
86+
SubMchID string `xml:"sub_mch_id,omitempty" json:"sub_mch_id,omitempty"`
8787
NonceStr string `xml:"nonce_str,omitempty" json:"nonce_str,omitempty"`
8888
ReqInfo string `xml:"req_info,omitempty" json:"req_info,omitempty"`
8989
}
9090

9191
// RefundNotifyDetail 退款详细信息
9292
type RefundNotifyDetail struct {
93-
TransactionId string `xml:"transaction_id,omitempty" json:"transaction_id,omitempty"`
93+
TransactionID string `xml:"transaction_id,omitempty" json:"transaction_id,omitempty"`
9494
OutTradeNo string `xml:"out_trade_no,omitempty" json:"out_trade_no,omitempty"`
95-
RefundId string `xml:"refund_id,omitempty" json:"refund_id,omitempty"`
95+
RefundID string `xml:"refund_id,omitempty" json:"refund_id,omitempty"`
9696
OutRefundNo string `xml:"out_refund_no,omitempty" json:"out_refund_no,omitempty"`
9797
TotalFee string `xml:"total_fee,omitempty" json:"total_fee,omitempty"`
9898
SettlementTotalFee string `xml:"settlement_total_fee,omitempty" json:"settlement_total_fee,omitempty"`

pay/server/server.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ func (server *Server) BatchQueryComment(params util.Params) (*base.Response, err
9898
// 如果出现错误,返回XML数据
9999
if strings.Index(xmlStr, "<") == 0 {
100100
return base.ProcessResponseXML(xmlStr)
101-
} else { // 正常返回csv数据
102-
return &base.Response{
103-
ReturnCode: "SUCCESS",
104-
ReturnMsg: "OK",
105-
Detail: xmlStr,
106-
}, nil
107101
}
102+
// 正常返回csv数据
103+
return &base.Response{
104+
ReturnCode: "SUCCESS",
105+
ReturnMsg: "OK",
106+
Detail: xmlStr,
107+
}, nil
108108
}

0 commit comments

Comments
 (0)