Skip to content

Commit

Permalink
新增 智慧商圈 相关接口
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoogle-ink committed Jun 19, 2021
1 parent 0fca43b commit 26c40a0
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
61 changes: 61 additions & 0 deletions wechat/v3/business_circle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package wechat

import (
"encoding/json"
"fmt"
"net/http"

"github.com/go-pay/gopay"
)

// 商圈积分同步API
// Code = 0 is success
// 文档:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_6_2.shtml
func (c *ClientV3) V3BusinessPointsSync(url string) (wxRsp *EmptyRsp, err error) {
bm := make(gopay.BodyMap)
bm.Set("url", url)
authorization, err := c.authorization(MethodPost, v3BusinessPointsSync, bm)
if err != nil {
return nil, err
}
res, si, bs, err := c.doProdPost(bm, v3BusinessPointsSync, authorization)
if err != nil {
return nil, err
}
wxRsp = &EmptyRsp{Code: Success, SignInfo: si}
if res.StatusCode != http.StatusNoContent {
wxRsp.Code = res.StatusCode
wxRsp.Error = string(bs)
return wxRsp, nil
}
return wxRsp, c.verifySyncSign(si)
}

// 商圈积分授权查询API
// Code = 0 is success
// 文档:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_6_4.shtml
func (c *ClientV3) V3BusinessAuthPointsQuery(appid, openid string) (*BusinessAuthPointsQueryRsp, error) {
if appid == "" {
appid = c.Appid
}
uri := fmt.Sprintf(v3BusinessAuthPointsQuery, openid) + "?appid=" + appid
authorization, err := c.authorization(MethodGet, uri, nil)
if err != nil {
return nil, err
}
res, si, bs, err := c.doProdGet(uri, authorization)
if err != nil {
return nil, err
}
wxRsp := &BusinessAuthPointsQueryRsp{Code: Success, SignInfo: si}
wxRsp.Response = new(BusinessAuthPointsQuery)
if err = json.Unmarshal(bs, wxRsp.Response); err != nil {
return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err)
}
if res.StatusCode != http.StatusOK {
wxRsp.Code = res.StatusCode
wxRsp.Error = string(bs)
return wxRsp, nil
}
return wxRsp, c.verifySyncSign(si)
}
38 changes: 38 additions & 0 deletions wechat/v3/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,44 @@ const (
v3GuideQuery = "/v3/smartguide/guides" // 服务人员查询 GET
v3GuideUpdate = "/v3/smartguide/guides/%s" // guide_id 服务人员信息更新 PATCH

// 智慧商圈
v3BusinessPointsSync = "/v3/businesscircle/points/notify" // 商圈积分同步 POST
v3BusinessAuthPointsQuery = "/v3/businesscircle/user-authorizations/%s" // openid 商圈积分授权查询 GET

// 代金券
v3CouponBatchCreate = "/v3/marketing/favor/coupon-stocks" // 创建代金券批次 POST
v3CouponBatchStart = "/v3/marketing/favor/stocks/%s/start" // stock_id 激活代金券批次 POST
v3CouponBatchGrant = "/v3/marketing/favor/users/%s/coupons" // openid 发放代金券批次 POST
v3CouponBatchPause = "/v3/marketing/favor/stocks/%s/pause" // stock_id 暂停代金券批次 POST
v3CouponBatchRestart = "/v3/marketing/favor/stocks/%s/restart" // stock_id 重启代金券批次 POST
v3CouponBatchQuery = "/v3/marketing/favor/stocks" // 条件查询批次列表 GET
v3CouponBatchDetail = "/v3/marketing/favor/stocks/%s" // stock_id 查询批次详情 GET
v3CouponDetailQuery = "/v3/marketing/favor/users/%s/coupons/%s" // openid、coupon_id 查询代金券详情 GET
v3CouponMerchantQuery = "/v3/marketing/favor/stocks/%s/merchants" // stock_id 查询代金券可用商户 GET
v3CouponItemQuery = "/v3/marketing/favor/stocks/%s/items" // stock_id 查询代金券可用单品 GET
v3UserCouponQuery = "/v3/marketing/favor/users/%s/coupons" // openid 根据商户号查用户的券 GET
v3CouponUseFlowDownload = "/v3/marketing/favor/stocks/%s/use-flow" // stock_id 下载批次核销明细 GET
v3CouponRefundFlowDownload = "/v3/marketing/favor/stocks/%s/refund-flow" // stock_id 下载批次退款明细 GET
v3CouponCallbackUrlSet = "/v3/marketing/favor/callbacks" // 设置消息通知地址 POST

// 商家券
v3BusiCouponBatchCreate = "/v3/marketing/busifavor/stocks" // 创建商家券 POST
v3BusiCouponBatchDetailQuery = "/v3/marketing/busifavor/stocks/%s" // stock_id 查询商家券详情 GET
v3BusiCouponUse = "/v3/marketing/busifavor/coupons/use" // 核销用户券 POST
v3UserBusiCouponQuery = "/v3/marketing/busifavor/users/%s/coupons" // openid 根据过滤条件查询用户券 GET
v3UserBusiCouponDetail = "/v3/marketing/busifavor/users/%s/coupons/%s/appids/%s" // openid、coupon_code、appid 查询用户单张券详情 GET
v3BusiCouponCodeUpload = "/v3/marketing/busifavor/stocks/%s/couponcodes" // stock_id 上传预存code POST
v3BusiCouponCallbackUrlSet = "/v3/marketing/busifavor/callbacks" // 设置商家券事件通知地址 POST
v3BusiCouponCallbackUrlQuery = "/v3/marketing/busifavor/callbacks" // 查询商家券事件通知地址 GET
v3BusiCouponAssociate = "/v3/marketing/busifavor/coupons/associate" // 关联订单信息 POST
v3BusiCouponDisassociate = "/v3/marketing/busifavor/coupons/disassociate" // 取消关联订单信息 POST
v3BusiCouponBatchUpdate = "/v3/marketing/busifavor/stocks/%s/budget" // stock_id 修改批次预算 PATCH
v3BusiCouponInfoUpdate = "/v3/marketing/busifavor/stocks/%s" // stock_id 修改商家券基本信息 PATCH
v3BusiCouponReturn = "/v3/marketing/busifavor/coupons/return" // 申请退券 POST
v3BusiCouponDeactivate = "/v3/marketing/busifavor/coupons/deactivate" // 使券失效 POST
v3MarketingSubsidy = "/v3/marketing/busifavor/subsidy/pay-receipts" // 营销补差付款 POST
v3MarketingSubsidyDetail = "/v3/marketing/busifavor/subsidy/pay-receipts/%s" // subsidy_receipt_id 查询营销补差付款单详情 GET

// 点金计划
v3GoldPlanManage = "/v3/goldplan/merchants/changegoldplanstatus" // 点金计划管理 POST
v3GoldPlanBillManage = "/v3/goldplan/merchants/changecustompagestatus" // 商家小票管理 POST
Expand Down
15 changes: 15 additions & 0 deletions wechat/v3/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,14 @@ type SmartGuideQueryRsp struct {
Error string `json:"-"`
}

// 商圈积分授权查询 Rsp
type BusinessAuthPointsQueryRsp struct {
Code int `json:"-"`
SignInfo *SignInfo `json:"-"`
Response *BusinessAuthPointsQuery `json:"response,omitempty"`
Error string `json:"-"`
}

// ==================================分割==================================

type JSAPIPayParams struct {
Expand Down Expand Up @@ -1047,3 +1055,10 @@ type SmartGuide struct {
Userid string `json:"userid,omitempty"` // 员工在商户企业微信通讯录使用的唯一标识,使用企业微信商家时返回
WorkId string `json:"work_id,omitempty"` // 服务人员通过小程序注册时填写的工号,使用个人微信商家时返回
}

type BusinessAuthPointsQuery struct {
Openid string `json:"openid"` // 顾客授权时使用的小程序上的openid
AuthorizeState string `json:"authorize_state"` // 顾客授权商圈积分结果:UNAUTHORIZED:未授权,AUTHORIZED:已授权,DEAUTHORIZED:已取消授权
AuthorizeTime string `json:"authorize_time,omitempty"` // 顾客成功授权商圈积分的时间
DeauthorizeTime string `json:"deauthorize_time,omitempty"` // 顾客关闭授权商圈积分的时间
}

0 comments on commit 26c40a0

Please sign in to comment.