-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
230 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package auth | ||
|
||
import "github.com/medivhzhan/weapp/v3/request" | ||
|
||
// 用户信息 | ||
type Auth struct { | ||
request *request.Request | ||
// 组成完整的 URL 地址 | ||
// 默认包含 AccessToken | ||
conbineURI func(url string, req interface{}) (string, error) | ||
} | ||
|
||
func NewAuth(request *request.Request, conbineURI func(url string, req interface{}) (string, error)) *Auth { | ||
sm := Auth{ | ||
request: request, | ||
conbineURI: conbineURI, | ||
} | ||
|
||
return &sm | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package auth | ||
|
||
import "github.com/medivhzhan/weapp/v3/request" | ||
|
||
const apiCheckEncryptedData = "/wxa/business/checkencryptedmsg" | ||
|
||
type CheckEncryptedDataRequest struct { | ||
// 必填 加密数据的sha256,通过Hex(Base16)编码后的字符串 | ||
EncryptedMsgHash string `json:"encrypted_msg_hash"` | ||
} | ||
|
||
type CheckEncryptedDataResponse struct { | ||
request.CommonError | ||
// 是否是合法的数据 | ||
Valid bool `json:"vaild"` | ||
// 加密数据生成的时间戳 | ||
CreateTime int64 `json:"create_time"` | ||
} | ||
|
||
// 检查加密信息是否由微信生成(当前只支持手机号加密数据),只能检测最近3天生成的加密数据 | ||
func (cli *Auth) CheckEncryptedData(req *CheckEncryptedDataRequest) (*CheckEncryptedDataResponse, error) { | ||
|
||
api, err := cli.conbineURI(apiCheckEncryptedData, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res := new(CheckEncryptedDataResponse) | ||
err = cli.request.Post(api, req, res) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package auth | ||
|
||
import "github.com/medivhzhan/weapp/v3/request" | ||
|
||
const apiGetPaidUnionId = "/wxa/getpaidunionid" | ||
|
||
type GetPaidUnionIdRequest struct { | ||
// 必填 支付用户唯一标识 | ||
Openid string `json:"openid"` | ||
// 非必填 微信支付订单号 | ||
TransactionId string `json:"transaction_id"` | ||
// 非必填 微信支付分配的商户号,和商户订单号配合使用 | ||
MchId string `json:"mch_id"` | ||
// 非必填 微信支付商户订单号,和商户号配合使用 | ||
OutTradeNo string `json:"out_trade_no"` | ||
} | ||
|
||
type GetPaidUnionIdResponse struct { | ||
request.CommonError | ||
// 用户唯一标识,调用成功后返回 | ||
UnionID string `json:"unionid"` | ||
} | ||
|
||
// 用户支付完成后,获取该用户的 UnionId,无需用户授权。 | ||
func (cli *Auth) GetPaidUnionId(req *GetPaidUnionIdRequest) (*GetPaidUnionIdResponse, error) { | ||
|
||
api, err := cli.conbineURI(apiGetPaidUnionId, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res := new(GetPaidUnionIdResponse) | ||
err = cli.request.Get(api, res) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package livebroadcast | ||
|
||
import "github.com/medivhzhan/weapp/v3/request" | ||
|
||
const apiGetSubAnchor = "/wxaapi/broadcast/room/GetSubAnchor" | ||
|
||
type GetSubAnchorRequest struct { | ||
// 房间ID | ||
RoomId int64 `json:"roomId"` | ||
} | ||
|
||
type GetSubAnchorResponse struct { | ||
request.CommonError | ||
Username string `json:"username"` | ||
} | ||
|
||
// 获取主播副号 | ||
func (cli *LiveBroadcast) GetSubAnchor(req *GetSubAnchorRequest) (*GetSubAnchorResponse, error) { | ||
|
||
api, err := cli.conbineURI(apiGetSubAnchor, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res := new(GetSubAnchorResponse) | ||
err = cli.request.Get(api, res) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package livebroadcast | ||
|
||
import "github.com/medivhzhan/weapp/v3/request" | ||
|
||
const apiGoodsAdd = "/wxaapi/broadcast/goods/add" | ||
|
||
type GoodsAddRequest struct { | ||
// 商品信息 | ||
GoodsInfo GoodsInfo `json:"goodsInfo"` | ||
} | ||
|
||
type GoodsInfo struct { | ||
// 必填 填入mediaID(mediaID获取后,三天内有效);图片mediaID的获取,请参考以下文档: https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html;图片规则:图片尺寸最大300像素*300像素; | ||
CoverImgUrl string `json:"coverImgUrl"` | ||
// 必填 商品名称,最长14个汉字,1个汉字相当于2个字符 | ||
Name string `json:"name"` | ||
// 必填 价格类型,1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必传) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必传) | ||
PriceType PriceType `json:"priceType"` | ||
// 必填 数字,最多保留两位小数,单位元 | ||
Price float64 `json:"price"` | ||
// 非必填 数字,最多保留两位小数,单位元 | ||
Price2 float64 `json:"price2"` | ||
// 必填 商品详情页的小程序路径,路径参数存在 url 的,该参数的值需要进行 encode 处理再填入 | ||
Url string `json:"url"` | ||
// 非必填 当商品为第三方小程序的商品则填写为对应第三方小程序的appid,自身小程序商品则为'' | ||
ThirdPartyAppid string `json:"thirdPartyAppid"` | ||
} | ||
|
||
type GoodsAddResponse struct { | ||
request.CommonError | ||
// 商品ID | ||
GoodsId string `json:"goodsId"` | ||
// 审核单ID | ||
AuditId string `json:"auditId"` | ||
} | ||
|
||
// 商品添加并提审 | ||
func (cli *LiveBroadcast) GoodsAdd(req *GoodsAddRequest) (*GoodsAddResponse, error) { | ||
|
||
api, err := cli.conbineURI(apiGoodsAdd, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res := new(GoodsAddResponse) | ||
err = cli.request.Post(api, req, res) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters