Skip to content

Commit 26c40a0

Browse files
committed
新增 智慧商圈 相关接口
1 parent 0fca43b commit 26c40a0

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

wechat/v3/business_circle.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package wechat
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"net/http"
7+
8+
"github.com/go-pay/gopay"
9+
)
10+
11+
// 商圈积分同步API
12+
// Code = 0 is success
13+
// 文档:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_6_2.shtml
14+
func (c *ClientV3) V3BusinessPointsSync(url string) (wxRsp *EmptyRsp, err error) {
15+
bm := make(gopay.BodyMap)
16+
bm.Set("url", url)
17+
authorization, err := c.authorization(MethodPost, v3BusinessPointsSync, bm)
18+
if err != nil {
19+
return nil, err
20+
}
21+
res, si, bs, err := c.doProdPost(bm, v3BusinessPointsSync, authorization)
22+
if err != nil {
23+
return nil, err
24+
}
25+
wxRsp = &EmptyRsp{Code: Success, SignInfo: si}
26+
if res.StatusCode != http.StatusNoContent {
27+
wxRsp.Code = res.StatusCode
28+
wxRsp.Error = string(bs)
29+
return wxRsp, nil
30+
}
31+
return wxRsp, c.verifySyncSign(si)
32+
}
33+
34+
// 商圈积分授权查询API
35+
// Code = 0 is success
36+
// 文档:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_6_4.shtml
37+
func (c *ClientV3) V3BusinessAuthPointsQuery(appid, openid string) (*BusinessAuthPointsQueryRsp, error) {
38+
if appid == "" {
39+
appid = c.Appid
40+
}
41+
uri := fmt.Sprintf(v3BusinessAuthPointsQuery, openid) + "?appid=" + appid
42+
authorization, err := c.authorization(MethodGet, uri, nil)
43+
if err != nil {
44+
return nil, err
45+
}
46+
res, si, bs, err := c.doProdGet(uri, authorization)
47+
if err != nil {
48+
return nil, err
49+
}
50+
wxRsp := &BusinessAuthPointsQueryRsp{Code: Success, SignInfo: si}
51+
wxRsp.Response = new(BusinessAuthPointsQuery)
52+
if err = json.Unmarshal(bs, wxRsp.Response); err != nil {
53+
return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err)
54+
}
55+
if res.StatusCode != http.StatusOK {
56+
wxRsp.Code = res.StatusCode
57+
wxRsp.Error = string(bs)
58+
return wxRsp, nil
59+
}
60+
return wxRsp, c.verifySyncSign(si)
61+
}

wechat/v3/constant.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,44 @@ const (
9090
v3GuideQuery = "/v3/smartguide/guides" // 服务人员查询 GET
9191
v3GuideUpdate = "/v3/smartguide/guides/%s" // guide_id 服务人员信息更新 PATCH
9292

93+
// 智慧商圈
94+
v3BusinessPointsSync = "/v3/businesscircle/points/notify" // 商圈积分同步 POST
95+
v3BusinessAuthPointsQuery = "/v3/businesscircle/user-authorizations/%s" // openid 商圈积分授权查询 GET
96+
97+
// 代金券
98+
v3CouponBatchCreate = "/v3/marketing/favor/coupon-stocks" // 创建代金券批次 POST
99+
v3CouponBatchStart = "/v3/marketing/favor/stocks/%s/start" // stock_id 激活代金券批次 POST
100+
v3CouponBatchGrant = "/v3/marketing/favor/users/%s/coupons" // openid 发放代金券批次 POST
101+
v3CouponBatchPause = "/v3/marketing/favor/stocks/%s/pause" // stock_id 暂停代金券批次 POST
102+
v3CouponBatchRestart = "/v3/marketing/favor/stocks/%s/restart" // stock_id 重启代金券批次 POST
103+
v3CouponBatchQuery = "/v3/marketing/favor/stocks" // 条件查询批次列表 GET
104+
v3CouponBatchDetail = "/v3/marketing/favor/stocks/%s" // stock_id 查询批次详情 GET
105+
v3CouponDetailQuery = "/v3/marketing/favor/users/%s/coupons/%s" // openid、coupon_id 查询代金券详情 GET
106+
v3CouponMerchantQuery = "/v3/marketing/favor/stocks/%s/merchants" // stock_id 查询代金券可用商户 GET
107+
v3CouponItemQuery = "/v3/marketing/favor/stocks/%s/items" // stock_id 查询代金券可用单品 GET
108+
v3UserCouponQuery = "/v3/marketing/favor/users/%s/coupons" // openid 根据商户号查用户的券 GET
109+
v3CouponUseFlowDownload = "/v3/marketing/favor/stocks/%s/use-flow" // stock_id 下载批次核销明细 GET
110+
v3CouponRefundFlowDownload = "/v3/marketing/favor/stocks/%s/refund-flow" // stock_id 下载批次退款明细 GET
111+
v3CouponCallbackUrlSet = "/v3/marketing/favor/callbacks" // 设置消息通知地址 POST
112+
113+
// 商家券
114+
v3BusiCouponBatchCreate = "/v3/marketing/busifavor/stocks" // 创建商家券 POST
115+
v3BusiCouponBatchDetailQuery = "/v3/marketing/busifavor/stocks/%s" // stock_id 查询商家券详情 GET
116+
v3BusiCouponUse = "/v3/marketing/busifavor/coupons/use" // 核销用户券 POST
117+
v3UserBusiCouponQuery = "/v3/marketing/busifavor/users/%s/coupons" // openid 根据过滤条件查询用户券 GET
118+
v3UserBusiCouponDetail = "/v3/marketing/busifavor/users/%s/coupons/%s/appids/%s" // openid、coupon_code、appid 查询用户单张券详情 GET
119+
v3BusiCouponCodeUpload = "/v3/marketing/busifavor/stocks/%s/couponcodes" // stock_id 上传预存code POST
120+
v3BusiCouponCallbackUrlSet = "/v3/marketing/busifavor/callbacks" // 设置商家券事件通知地址 POST
121+
v3BusiCouponCallbackUrlQuery = "/v3/marketing/busifavor/callbacks" // 查询商家券事件通知地址 GET
122+
v3BusiCouponAssociate = "/v3/marketing/busifavor/coupons/associate" // 关联订单信息 POST
123+
v3BusiCouponDisassociate = "/v3/marketing/busifavor/coupons/disassociate" // 取消关联订单信息 POST
124+
v3BusiCouponBatchUpdate = "/v3/marketing/busifavor/stocks/%s/budget" // stock_id 修改批次预算 PATCH
125+
v3BusiCouponInfoUpdate = "/v3/marketing/busifavor/stocks/%s" // stock_id 修改商家券基本信息 PATCH
126+
v3BusiCouponReturn = "/v3/marketing/busifavor/coupons/return" // 申请退券 POST
127+
v3BusiCouponDeactivate = "/v3/marketing/busifavor/coupons/deactivate" // 使券失效 POST
128+
v3MarketingSubsidy = "/v3/marketing/busifavor/subsidy/pay-receipts" // 营销补差付款 POST
129+
v3MarketingSubsidyDetail = "/v3/marketing/busifavor/subsidy/pay-receipts/%s" // subsidy_receipt_id 查询营销补差付款单详情 GET
130+
93131
// 点金计划
94132
v3GoldPlanManage = "/v3/goldplan/merchants/changegoldplanstatus" // 点金计划管理 POST
95133
v3GoldPlanBillManage = "/v3/goldplan/merchants/changecustompagestatus" // 商家小票管理 POST

wechat/v3/model.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,14 @@ type SmartGuideQueryRsp struct {
326326
Error string `json:"-"`
327327
}
328328

329+
// 商圈积分授权查询 Rsp
330+
type BusinessAuthPointsQueryRsp struct {
331+
Code int `json:"-"`
332+
SignInfo *SignInfo `json:"-"`
333+
Response *BusinessAuthPointsQuery `json:"response,omitempty"`
334+
Error string `json:"-"`
335+
}
336+
329337
// ==================================分割==================================
330338

331339
type JSAPIPayParams struct {
@@ -1047,3 +1055,10 @@ type SmartGuide struct {
10471055
Userid string `json:"userid,omitempty"` // 员工在商户企业微信通讯录使用的唯一标识,使用企业微信商家时返回
10481056
WorkId string `json:"work_id,omitempty"` // 服务人员通过小程序注册时填写的工号,使用个人微信商家时返回
10491057
}
1058+
1059+
type BusinessAuthPointsQuery struct {
1060+
Openid string `json:"openid"` // 顾客授权时使用的小程序上的openid
1061+
AuthorizeState string `json:"authorize_state"` // 顾客授权商圈积分结果:UNAUTHORIZED:未授权,AUTHORIZED:已授权,DEAUTHORIZED:已取消授权
1062+
AuthorizeTime string `json:"authorize_time,omitempty"` // 顾客成功授权商圈积分的时间
1063+
DeauthorizeTime string `json:"deauthorize_time,omitempty"` // 顾客关闭授权商圈积分的时间
1064+
}

0 commit comments

Comments
 (0)