|
@ -0,0 +1,82 @@
|
|
|
package com.yihu.wlyy.web.third.template;
|
|
|
|
|
|
import com.yihu.wlyy.aop.ObserverRequired;
|
|
|
import com.yihu.wlyy.web.BaseController;
|
|
|
import com.yihu.wlyy.wechat.util.WeiXinTempMsgSendUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
/**
|
|
|
* 第三方推往健康模板消息
|
|
|
* Created by Reece on 2017/11/14.
|
|
|
*/
|
|
|
@Controller
|
|
|
@RestController
|
|
|
@RequestMapping(value = "/third/template")
|
|
|
@Api(description = "第三方推往健康模板消息")
|
|
|
public class ThirdTemplateController extends BaseController {
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
private WeiXinTempMsgSendUtils tempMsgSendUtils;
|
|
|
@Value("${wechat.message.template_doctor_survey}")
|
|
|
private String template_doctor_survey;
|
|
|
|
|
|
/**
|
|
|
* 发送模板消息
|
|
|
*
|
|
|
* @param type 消息类别
|
|
|
* @param toUser 接受者openID
|
|
|
* @param url 跳转路径(带参数)
|
|
|
* @param first
|
|
|
* @param remark
|
|
|
* @param keywords
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/sendTemplate", method = RequestMethod.POST)
|
|
|
@ApiOperation(value = "发送模板消息")
|
|
|
@ResponseBody
|
|
|
@ObserverRequired
|
|
|
public String sendTemplate(
|
|
|
@RequestParam(required = true) String type,
|
|
|
@RequestParam(required = true) String toUser,
|
|
|
@RequestParam(required = false) String url,
|
|
|
@RequestParam(required = true) String first,
|
|
|
@RequestParam(required = true) String remark,
|
|
|
@RequestParam(required = true) String... keywords) {
|
|
|
try {
|
|
|
JSONObject data = tempMsgSendUtils.packageTemplate(first, remark, keywords);
|
|
|
String templateId = getTemplateId(type);
|
|
|
tempMsgSendUtils.sendTemplateMessage(templateId, toUser, url, data);
|
|
|
return write(200, "发送成功!");
|
|
|
} catch (Exception e) {
|
|
|
error(e);
|
|
|
return invalidUserException(e, -1, "发送失败!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据第三方type 匹配对应模板ID
|
|
|
*
|
|
|
* @param type 1.代办事项
|
|
|
* @return
|
|
|
*/
|
|
|
private String getTemplateId(String type) throws Exception {
|
|
|
String templateId = null;
|
|
|
switch (type) {
|
|
|
case "1":
|
|
|
templateId = template_doctor_survey;
|
|
|
break;
|
|
|
default:
|
|
|
templateId = template_doctor_survey;
|
|
|
break;
|
|
|
}
|
|
|
return templateId;
|
|
|
}
|
|
|
|
|
|
}
|