Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
2ca77442
Commit
2ca77442
authored
Dec 19, 2023
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
公众号消息测试
parent
f4af76be
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
99 additions
and
10 deletions
+99
-10
ch-core/src/main/java/com/wwdz/ch/core/entity/ConsignSaleSubscribeMsg.java
...java/com/wwdz/ch/core/entity/ConsignSaleSubscribeMsg.java
+46
-0
ch-core/src/main/resources/application-dev.yml
ch-core/src/main/resources/application-dev.yml
+1
-0
ch-core/src/main/resources/application-prod.yml
ch-core/src/main/resources/application-prod.yml
+1
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/OfficialAccountApi.java
.../src/main/java/com/wwdz/ch/wx/api/OfficialAccountApi.java
+5
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/OfficialAccountCallbackController.java
...com/wwdz/ch/wx/api/OfficialAccountCallbackController.java
+24
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/OfficialAccountController.java
...in/java/com/wwdz/ch/wx/web/OfficialAccountController.java
+11
-4
ch-wx-api/src/test/java/com/wwdz/ch/wx/api/OfficialAccountApiTest.java
.../test/java/com/wwdz/ch/wx/api/OfficialAccountApiTest.java
+11
-5
No files found.
ch-core/src/main/java/com/wwdz/ch/core/entity/ConsignSaleSubscribeMsg.java
0 → 100644
View file @
2ca77442
package
com.wwdz.ch.core.entity
;
import
com.xxdxxs.entity.Entity
;
import
lombok.Data
;
import
java.util.HashMap
;
import
java.util.Map
;
@Data
public
class
ConsignSaleSubscribeMsg
implements
Entity
,
AbstractSubscribeMsg
{
private
String
templetId
;
/**
* 寄售单号
*/
private
String
saleId
;
/**
* 商品名称
* 会拼接上预估的价格
*/
private
String
itemName
;
/**
* 寄售单号
* 估价的时间
*/
private
String
time
;
@Override
public
Map
<
String
,
Object
>
getTempletParam
()
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"character_string1.DATA"
,
new
HashMap
(){{
put
(
"value"
,
saleId
);}});
map
.
put
(
"thing2.DATA"
,
new
HashMap
(){{
put
(
"value"
,
itemName
);}});
map
.
put
(
"time4.DATA"
,
new
HashMap
(){{
put
(
"value"
,
time
);}});
return
map
;
}
@Override
public
String
getTempletId
()
{
return
templetId
;
}
}
ch-core/src/main/resources/application-dev.yml
View file @
2ca77442
...
...
@@ -21,6 +21,7 @@ dts:
officialaccount-token
:
Uu6GHYOiP1xJ6GaBMyXfnITufAGJTe3Q
officialaccount-key
:
noeN1amYRvzrVmE2GnC5VnsIfgPEmv6bhX54wJOARlM
get-officialaccount-accesstoken-url
:
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s
officialaccount-templetId
:
WJkhzyY0_7AYqh19_ujK9yZhj4HohF8ETJvG5NYA9A8
#腾讯IM配置
im
:
...
...
ch-core/src/main/resources/application-prod.yml
View file @
2ca77442
...
...
@@ -20,6 +20,7 @@ dts:
officialaccount-token
:
Uu6GHYOiP1xJ6GaBMyXfnITufAGJTe3Q
officialaccount-key
:
noeN1amYRvzrVmE2GnC5VnsIfgPEmv6bhX54wJOARlM
get-officialaccount-accesstoken-url
:
https://api.weixin.qq.com/cgi-bin/stable_token
officialaccount-templetId
:
WJkhzyY0_7AYqh19_ujK9yZhj4HohF8ETJvG5NYA9A8
#腾讯IM配置
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/OfficialAccountApi.java
View file @
2ca77442
...
...
@@ -41,6 +41,9 @@ public class OfficialAccountApi {
@Value
(
"${dts.wx.officialaccount-secret}"
)
private
String
OFFICIAL_ACCOUNT_APPSECRET
;
@Value
(
"${dts.wx.officialaccount-templetId}"
)
private
String
OFFICIALACCOUNT_TEMPLETID
;
@Value
(
"${dts.wx.app-id}"
)
private
String
APPLET_APPID
;
...
...
@@ -59,6 +62,7 @@ public class OfficialAccountApi {
String
accessTokenUrl
=
String
.
format
(
GET_OFFICIAL_ACCOUNT_ACCESSTOKEN_URL
,
OFFICIAL_ACCOUNT_APPID
,
OFFICIAL_ACCOUNT_APPSECRET
);
String
res
=
OkHttpUtil
.
builder
().
url
(
accessTokenUrl
)
.
get
().
sync
();
logger
.
info
(
"测试环境获取token返回结果: {}"
,
res
);
String
token
=
JsonUtils
.
getValueByPath
(
res
,
"access_token"
);
return
token
;
}
...
...
@@ -147,7 +151,7 @@ public class OfficialAccountApi {
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"touser"
,
openId
);
map
.
put
(
"template_id"
,
abstractSubscribeMsg
.
getTempletId
()
);
map
.
put
(
"template_id"
,
OFFICIALACCOUNT_TEMPLETID
);
Map
<
String
,
Object
>
miniprogramMap
=
new
HashMap
<>();
String
link
=
wxLoginManager
.
getLink
(
MSG_URL
);
miniprogramMap
.
put
(
"appid"
,
APPLET_APPID
);
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/OfficialAccountCallbackController.java
View file @
2ca77442
...
...
@@ -2,6 +2,7 @@ package com.wwdz.ch.wx.api;
import
com.wwdz.ch.core.consts.OfficalAccountEnum
;
import
com.wwdz.ch.core.entity.ConsignSaleSubscribeMsg
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.db.dao.UserDao
;
import
com.wwdz.ch.db.domain.OfficialAccountSubscribeRecord
;
...
...
@@ -9,8 +10,10 @@ import com.wwdz.ch.db.domain.User;
import
com.wwdz.ch.wx.api.aes.AesException
;
import
com.wwdz.ch.wx.api.aes.WXBizMsgCrypt
;
import
com.wwdz.ch.wx.service.OfficialAccountSubscribeRecordService
;
import
com.xxdxxs.utils.DateUtils
;
import
com.xxdxxs.utils.StringUtils
;
import
com.xxdxxs.utils.XmlUtils
;
import
io.swagger.annotations.ApiOperation
;
import
org.dom4j.DocumentException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -177,4 +180,25 @@ public class OfficialAccountCallbackController {
return
token
;
}
@ApiOperation
(
value
=
"测试发送消息"
)
@GetMapping
(
"/testForSendMsg"
)
public
Result
testForSendMsg
()
{
try
{
logger
.
info
(
"【请求开始】测试发送公众号消息"
);
String
openId
=
"oNPTN6QaVliZfKB53OzZRPBZr_r8"
;
String
saleId
=
"CSO2312151346268093384"
;
String
itemName
=
"测试商品"
+
" 图文估价为200-300元之间"
;
ConsignSaleSubscribeMsg
consignSaleSubscribeMsg
=
new
ConsignSaleSubscribeMsg
();
consignSaleSubscribeMsg
.
setSaleId
(
saleId
);
consignSaleSubscribeMsg
.
setItemName
(
itemName
);
consignSaleSubscribeMsg
.
setTime
(
DateUtils
.
toString
(
new
Date
()));
officialAccountApi
.
sendModelMsg
(
openId
,
consignSaleSubscribeMsg
);
return
Result
.
success
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"测试发送公众号消息 error:{}"
,
e
);
}
return
Result
.
failed
();
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/OfficialAccountController.java
View file @
2ca77442
...
...
@@ -3,20 +3,22 @@ package com.wwdz.ch.wx.web;
import
com.alibaba.fastjson.JSON
;
import
com.wwdz.ch.core.consts.ResultCode
;
import
com.wwdz.ch.core.entity.ConsignSaleSubscribeMsg
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.db.domain.User
;
import
com.wwdz.ch.db.dto.request.UserRequestDto
;
import
com.wwdz.ch.wx.api.OfficialAccountApi
;
import
com.wwdz.ch.wx.service.OfficialAccountSubscribeRecordService
;
import
com.wwdz.ch.wx.service.UserService
;
import
com.xxdxxs.utils.DateUtils
;
import
io.swagger.annotations.ApiOperation
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Date
;
@RestController
@RequestMapping
(
"/wx/officialAccount"
)
...
...
@@ -30,6 +32,9 @@ public class OfficialAccountController {
@Autowired
UserService
userService
;
@Autowired
OfficialAccountApi
officialAccountApi
;
@ApiOperation
(
value
=
"判断用户是否关注过公众号"
)
@PostMapping
(
"/isSubscribed"
)
public
Result
isSubscribed
(
@RequestBody
UserRequestDto
dto
)
{
...
...
@@ -47,4 +52,6 @@ public class OfficialAccountController {
}
return
officialAccountSubscribeRecordService
.
isSubscribed
(
unionid
);
}
}
ch-wx-api/src/test/java/com/wwdz/ch/wx/api/OfficialAccountApiTest.java
View file @
2ca77442
package
com.wwdz.ch.wx.api
;
import
com.wwdz.ch.core.entity.ConsignSaleSubscribeMsg
;
import
com.wwdz.ch.core.entity.OfficialAccountFollowSubscribeMsg
;
import
com.xxdxxs.utils.DateUtils
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
java.util.Date
;
@SpringBootTest
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
public
class
OfficialAccountApiTest
{
...
...
@@ -29,10 +33,12 @@ public class OfficialAccountApiTest {
@Test
public
void
sendSubscribeMsg
()
{
String
openId
=
"oNPTN6QaVliZfKB53OzZRPBZr_r8"
;
OfficialAccountFollowSubscribeMsg
officialAccountFollowSubscribeMsg
=
new
OfficialAccountFollowSubscribeMsg
();
officialAccountFollowSubscribeMsg
.
setFollowUser
(
"测试用户"
);
officialAccountFollowSubscribeMsg
.
setTip
(
"测试帖子"
);
officialAccountFollowSubscribeMsg
.
setFollowTime
(
"2023-10-16 06:00:11"
);
officialAccountApi
.
sendModelMsg
(
openId
,
officialAccountFollowSubscribeMsg
);
String
saleId
=
"CSO2312151346268093384"
;
String
itemName
=
"测试商品"
+
" 图文估价为200-300元之间"
;
ConsignSaleSubscribeMsg
consignSaleSubscribeMsg
=
new
ConsignSaleSubscribeMsg
();
consignSaleSubscribeMsg
.
setSaleId
(
saleId
);
consignSaleSubscribeMsg
.
setItemName
(
itemName
);
consignSaleSubscribeMsg
.
setTime
(
DateUtils
.
toString
(
new
Date
()));
officialAccountApi
.
sendModelMsg
(
openId
,
consignSaleSubscribeMsg
);
}
}
\ No newline at end of file
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