Commit 72825ce3 by zhanghj

V1.1.0--提交发送公众号模板相关接口

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@19799 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 4075c019
...@@ -57,6 +57,7 @@ public class WechatUtils { ...@@ -57,6 +57,7 @@ public class WechatUtils {
public String GET_OPENID_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$APPID$&secret=$SECRET$&code=$CODE$&grant_type=authorization_code"; public String GET_OPENID_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$APPID$&secret=$SECRET$&code=$CODE$&grant_type=authorization_code";
public String SEND_MESSAGE_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="; public String SEND_MESSAGE_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";
public String GET_USER_INFO_URL = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=$ACCESS_TOKEN$&openid=$OPENID$&lang=zh_CN"; public String GET_USER_INFO_URL = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=$ACCESS_TOKEN$&openid=$OPENID$&lang=zh_CN";
public String GET_WECHAT_PUBLIC_CODE = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$APPID$&redirect_uri=$REDIRECT_URI$&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
@Resource @Resource
RedisCacheUtil redisCacheUtil; RedisCacheUtil redisCacheUtil;
...@@ -302,4 +303,6 @@ public class WechatUtils { ...@@ -302,4 +303,6 @@ public class WechatUtils {
return result; return result;
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -37,10 +37,6 @@ ...@@ -37,10 +37,6 @@
</dependency> </dependency>
<!-- EurekaClient --> <!-- EurekaClient -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency> </dependency>
......
...@@ -10,21 +10,24 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -10,21 +10,24 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.glsx.common.annotation.AuthCheck;
import com.glsx.common.constants.ResultObject; import com.glsx.common.constants.ResultObject;
import com.glsx.common.utils.Page; import com.glsx.common.utils.Page;
import com.glsx.common.utils.PropertiesUtil; import com.glsx.common.utils.PropertiesUtil;
import com.glsx.common.utils.wehcat.TemplateData;
import com.glsx.common.utils.wehcat.WechatTemplate;
import com.glsx.common.utils.wehcat.WechatUtils;
import com.glsx.ordercenter.constants.ResultCodeEnum; import com.glsx.ordercenter.constants.ResultCodeEnum;
import com.glsx.ordercenter.pojo.Test; import com.glsx.ordercenter.pojo.Test;
import com.glsx.ordercenter.service.TestService; import com.glsx.ordercenter.service.TestService;
@AuthCheck
@RestController @RestController
@RequestMapping(value="/test") @RequestMapping(value="/test")
public class TestController { public class TestController {
@Autowired @Autowired
private TestService testService; private TestService testService;
@Autowired
private WechatUtils wechatUtils;
@RequestMapping(value="/get", method={RequestMethod.GET, RequestMethod.POST}) @RequestMapping(value="/get", method={RequestMethod.GET, RequestMethod.POST})
public ResultObject index(Test test){ public ResultObject index(Test test){
...@@ -64,4 +67,27 @@ public class TestController { ...@@ -64,4 +67,27 @@ public class TestController {
public ResultObject testException() throws Exception{ public ResultObject testException() throws Exception{
throw new Exception(); throw new Exception();
} }
@RequestMapping(value="/sendTemplateMsg")
public ResultObject sendTemplateMsg(){
WechatTemplate wechatTemplate = new WechatTemplate();
String templateId = "I0o6IxHuPxVV8KcLOgdgC4kqe_0_dUDHwyFBE927Ha4";
String wxOpenId = "o-M5g1YISHqiOSmgLtUT6uUGzGHE";
String url = "";
wechatTemplate.setTemplate_id(templateId);
wechatTemplate.setTouser(wxOpenId);
wechatTemplate.setUrl(url);
Map<String, TemplateData> data = new HashMap<String, TemplateData>();
data.put("first", new TemplateData("您的订单已超时", ""));
data.put("keyword1", new TemplateData("12222222", ""));
data.put("keyword2", new TemplateData("June", ""));
data.put("keyword3", new TemplateData("185766733306", ""));
data.put("keyword4", new TemplateData("2019-04-17", ""));
data.put("remark", new TemplateData("如有疑问,请联系客服,客服热线:0755-32982755", ""));
wechatTemplate.setData(data);
wechatUtils.sendTemplateMessage(wechatTemplate);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg());
}
} }
...@@ -37,10 +37,6 @@ ...@@ -37,10 +37,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- spring-boot-devtools --> <!-- spring-boot-devtools -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
......
...@@ -23,6 +23,11 @@ ...@@ -23,6 +23,11 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>car-service-common</artifactId>
<version>1.0.0</version>
</dependency>
<!-- spring-boot-devtools --> <!-- spring-boot-devtools -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
......
...@@ -10,6 +10,8 @@ import org.springframework.boot.web.servlet.ServletComponentScan; ...@@ -10,6 +10,8 @@ import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
...@@ -27,8 +29,9 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; ...@@ -27,8 +29,9 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableEurekaClient @EnableEurekaClient
@EnableTransactionManagement @EnableTransactionManagement
@EnableDiscoveryClient @EnableDiscoveryClient
@ComponentScan(basePackages="com.glsx.common")
@EnableFeignClients(basePackages = {"com.glsx.common.feign.client"})
@MapperScan(basePackages={"com.glsx.task.mapper"}) @MapperScan(basePackages={"com.glsx.task.mapper"})
@EnableScheduling
public class Application extends SpringBootServletInitializer{ public class Application extends SpringBootServletInitializer{
/** /**
......
package com.glsx.task.constants;
/**
*
* @Title Constant.java
* @Package com.glsx.task.constants
* @Description TODO
* @author zhanghj
* @date 2019年4月16日 上午11:02:28
* @version 1.0.0
*/
public class Constant {
}
...@@ -2,21 +2,73 @@ package com.glsx.task.schedule; ...@@ -2,21 +2,73 @@ package com.glsx.task.schedule;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.glsx.common.utils.wehcat.TemplateData;
import com.glsx.common.utils.wehcat.WechatTemplate;
import com.glsx.common.utils.wehcat.WechatUtils;
/**
*
* @Title ScheduledTasks.java
* @Package com.glsx.task.schedule
* @Description TODO 定时任务类
* @author zhanghj
* @date 2019年4月16日 上午10:17:08
* @version 1.0.0
*/
@EnableScheduling
@Configurable
@Component @Component
public class ScheduledTasks { public class ScheduledTasks {
private static final Logger log = LoggerFactory.getLogger(ScheduledTasks.class); private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class);
@Autowired
private WechatUtils wechatUtils;
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
@Scheduled(fixedRate = 5000) @Scheduled(fixedRate = 5000)
public void reportCurrentTime() { public void reportCurrentTime() {
log.info("The time is now {}", dateFormat.format(new Date())); logger.info("The time is now {}", dateFormat.format(new Date()));
}
/**
*
* @author zhanghj
* @Title: orderTimeoutRemind
* @Description: TODO 订单超时提醒,每1分钟跑一次定时任务
* void
*
*/
@Scheduled(cron = "0 0/1 * * * ?")
public void orderTimeoutRemind() {
logger.info("定时任务超时提醒----------------------->");
WechatTemplate wechatTemplate = new WechatTemplate();
String templateId = "I0o6IxHuPxVV8KcLOgdgC4kqe_0_dUDHwyFBE927";
String wxOpenId = "o-M5g1YISHqiOSmgLtUT6uUGzGHE";
wechatTemplate.setTemplate_id(templateId);
wechatTemplate.setTouser(wxOpenId);
//wechatTemplate.setUrl(url);
Map<String, TemplateData> data = new HashMap<String, TemplateData>();
data.put("first", new TemplateData("您的订单已超时", ""));
data.put("keyword1", new TemplateData("12222222", ""));
data.put("keyword2", new TemplateData("June", ""));
data.put("keyword3", new TemplateData("185766733306", ""));
data.put("keyword4", new TemplateData("2019-04-17", ""));
data.put("remark", new TemplateData("如有疑问,请联系客服,客服热线:0755-32982755", ""));
wechatTemplate.setData(data);
wechatUtils.sendTemplateMessage(wechatTemplate);
} }
} }
...@@ -21,4 +21,4 @@ ALTER TABLE `sys_order` ...@@ -21,4 +21,4 @@ ALTER TABLE `sys_order`
ADD COLUMN `channel` varchar(64) NULL DEFAULT '' COMMENT '渠道编码'; ADD COLUMN `channel` varchar(64) NULL DEFAULT '' COMMENT '渠道编码';
ALTER TABLE `sys_order` ALTER TABLE `sys_order`
ADD COLUMN `merchant_username` varchar(64) NULL DEFAULT '' COMMENT '所属商户的用户名(用户名是可随意改变的)';
\ No newline at end of file \ No newline at end of file
ADD COLUMN `merchant_name` varchar(255) NULL DEFAULT '' COMMENT '所属商户名称';
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!