|
|
@@ -23,6 +23,7 @@ import com.tuoheng.miniprogram.utils.GetOpenIdUtil; |
|
|
|
import com.tuoheng.miniprogram.vo.WxAuthorizeVo; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.web.client.RestClientException; |
|
|
@@ -51,6 +52,9 @@ public class WxServiceImpl implements IWxService { |
|
|
|
|
|
|
|
private static long expiresTime; |
|
|
|
|
|
|
|
@Value("${wx.miniprogramState:}") |
|
|
|
private String miniprogramState; |
|
|
|
|
|
|
|
public JsonResult checkAuthorize(String code) { |
|
|
|
log.info("进入判断用户是否授权接口, code={}", code); |
|
|
|
User user = CurrentUserUtil.getUserInfo(); |
|
|
@@ -195,8 +199,7 @@ public class WxServiceImpl implements IWxService { |
|
|
|
//本次结束,进入下次循环 |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (user.getAuthorize() == AuthorizeStatusEnum.AUTHORIZE_ON.getCode() |
|
|
|
&& user.getSubscribeTimes() == SubscribeTimesEnum.SUBSCRIBE_TIMES_NO_ONE.getCode()) { |
|
|
|
if (user.getAuthorize() == AuthorizeStatusEnum.AUTHORIZE_ON.getCode() && user.getSubscribeTimes() == SubscribeTimesEnum.SUBSCRIBE_TIMES_NO_ONE.getCode()) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
//获取当前登录openId |
|
|
@@ -214,18 +217,17 @@ public class WxServiceImpl implements IWxService { |
|
|
|
String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + getAccessToken(); |
|
|
|
WxSendMessageParam param = new WxSendMessageParam(); |
|
|
|
param.setPage("/package_question/pages/taskList/taskList"); |
|
|
|
//param.setMiniprogram_state("formal"); |
|
|
|
param.setMiniprogram_state(miniprogramState); |
|
|
|
param.setTouser(openId); |
|
|
|
param.setTemplate_id(CommonConfig.templateId); |
|
|
|
Map<String, TemplateMinDto> data = new HashMap<>(3); |
|
|
|
//消息模板{{time12.DATA}} {{thing4.DATA}} {{thing13.DATA}} 时间格式一定是这样的2022-01-13 02:31:36 |
|
|
|
ResponseEntity<String> responseEntity = null; |
|
|
|
ResponseEntity<String> responseEntity; |
|
|
|
try { |
|
|
|
data.put("time12", new TemplateMinDto(wxMessageRequest.getCreateTime())); |
|
|
|
data.put("thing4", new TemplateMinDto(wxMessageRequest.getQuestionName())); |
|
|
|
data.put("thing13", new TemplateMinDto(wxMessageRequest.getQuestionDesc())); |
|
|
|
param.setData(data); |
|
|
|
|
|
|
|
responseEntity = restTemplate.postForEntity(url, param, String.class); |
|
|
|
String messageBody = responseEntity.getBody(); |
|
|
|
Integer errcode = JSONObject.parseObject(messageBody).getInteger("errcode").intValue(); |
|
|
@@ -243,18 +245,15 @@ public class WxServiceImpl implements IWxService { |
|
|
|
} |
|
|
|
JSONObject jsonObject = JSON.parseObject(messageBody); |
|
|
|
if (Objects.nonNull(jsonObject)) { |
|
|
|
log.info("openId:" + openId + "发送消息返回内容:" + jsonObject.toJSONString()); |
|
|
|
log.info("发送消息:userId={}, openId={},返回内容={}", userId, openId, jsonObject.toJSONString()); |
|
|
|
} |
|
|
|
isSend = true; |
|
|
|
} catch (RestClientException e) { |
|
|
|
log.info("openId:" + openId + "发送消息异常报错:" + e); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return JsonResult.success(isSend); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |