Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wechat-client-sdk
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
go
wechat-client-sdk
Commits
3126ec25
Commit
3126ec25
authored
Nov 18, 2022
by
yemin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
a440b760
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
2 deletions
+81
-2
watcherTasks.xml
.idea/watcherTasks.xml
+1
-1
go.mod
go.mod
+1
-1
Client.go
message/subscribe/Client.go
+69
-0
IfUtil.go
util/IfUtil.go
+10
-0
No files found.
.idea/watcherTasks.xml
View file @
3126ec25
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"ProjectTasksOptions"
>
<TaskOptions
isEnabled=
"
tru
e"
>
<TaskOptions
isEnabled=
"
fals
e"
>
<option
name=
"arguments"
value=
"fmt $FilePath$"
/>
<option
name=
"checkSyntaxErrors"
value=
"true"
/>
<option
name=
"description"
/>
...
...
go.mod
View file @
3126ec25
module git.168cad.top/go/wechat-client-sdk
go 1.1
7
go 1.1
8
require github.com/wechatpay-apiv3/wechatpay-go v0.2.16 // indirect
message/subscribe/Client.go
0 → 100644
View file @
3126ec25
package
subscribe
import
(
"encoding/json"
"errors"
"fmt"
"git.168cad.top/go/wechat-client-sdk/core/response"
"git.168cad.top/go/wechat-client-sdk/httpclient"
"git.168cad.top/go/wechat-client-sdk/util"
)
type
SendSubscribeMsgParam
struct
{
AccessToken
string
//接口调用凭证。使用access_token或者authorizer_access_token
TemplateId
string
//所需下发的订阅模板id
Page
string
//点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转
Touser
string
//接收者(用户)的 openid
Data
[]
*
SendSubscribeMsgDataParam
//模板内容
MiniprogramState
string
//跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
Lang
string
//进入小程序查看”的语言类型,支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN
}
type
SendSubscribeMsgDataParam
struct
{
Name
string
//
Value
string
//
}
type
subscribeMsgParam
struct
{
TemplateId
string
`json:"template_id"`
//所需下发的订阅模板id
Page
string
`json:"page"`
//点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转
Touser
string
`json:"touser"`
//接收者(用户)的 openid
Data
map
[
string
]
map
[
string
]
string
`json:"data"`
//模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }的object
MiniprogramState
string
`json:"miniprogram_state"`
//跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
Lang
string
`json:"lang"`
//进入小程序查看”的语言类型,支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN
}
// SendMeg 发送订阅消息
func
SendMeg
(
p
*
SendSubscribeMsgParam
)
error
{
url
:=
"https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="
+
p
.
AccessToken
d
:=
make
(
map
[
string
]
map
[
string
]
string
,
len
(
p
.
Page
))
for
_
,
datum
:=
range
p
.
Data
{
v
:=
make
(
map
[
string
]
string
,
1
)
v
[
"value"
]
=
datum
.
Value
d
[
datum
.
Name
]
=
v
}
bp
:=
subscribeMsgParam
{
TemplateId
:
p
.
TemplateId
,
Page
:
p
.
Page
,
Touser
:
p
.
Touser
,
Data
:
d
,
MiniprogramState
:
util
.
IF
(
p
.
MiniprogramState
==
""
,
"formal"
,
p
.
MiniprogramState
),
Lang
:
util
.
IF
(
p
.
Lang
==
""
,
"zh_CN"
,
p
.
Lang
),
}
sss
,
_
:=
json
.
Marshal
(
bp
)
fmt
.
Println
(
"发送请求内容:"
+
string
(
sss
))
bs
,
err
:=
httpclient
.
Post
(
url
,
nil
,
bp
)
if
err
!=
nil
{
return
err
}
r
:=
response
.
MiniProgramResponse
{}
err
=
json
.
Unmarshal
(
bs
,
&
r
)
if
err
!=
nil
{
return
err
}
if
r
.
ErrCode
!=
0
{
return
errors
.
New
(
r
.
ErrMSG
)
}
return
nil
}
util/IfUtil.go
0 → 100644
View file @
3126ec25
package
util
// IF 三元运算
func
IF
[
T
any
](
t
bool
,
a
T
,
b
T
)
T
{
if
t
{
return
a
}
else
{
return
b
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment