| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.xiaopeng.api.dto.account.UserResourcesDto; |
| | | import com.xiaopeng.api.feignClient.account.SSOClient; |
| | | import com.xiaopeng.api.vo.account.WechatAccessTokenResVo; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.exception.ServiceException; |
| | | import com.xiaopeng.common.core.utils.StringUtils; |
| | | import com.xiaopeng.common.redis.service.RedisService; |
| | | import com.xiaopeng.pushMessage.model.Category; |
| | |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | |
| | | @Value("${wx.appletsAppSecret:123456}") |
| | | private String wxAppletsAppSecret; |
| | | |
| | | @Value("${sso.appid}") |
| | | private String appId; |
| | | |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | | @Resource |
| | | private SSOClient ssoClient; |
| | | |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | String getToken(Boolean isRefresh){ |
| | | WechatAccessTokenResVo wechatAccessToken = ssoClient.getWechatAccessToken(appId, wxAppletsAppid, isRefresh); |
| | | if(null == wechatAccessToken){ |
| | | log.info("获取微信access_token失败"); |
| | | throw new ServiceException("获取微信access_token失败"); |
| | | } |
| | | if(0 != wechatAccessToken.getCode()){ |
| | | log.info("获取微信access_token失败:{}", wechatAccessToken.getMsg()); |
| | | throw new ServiceException("获取微信access_token失败"); |
| | | } |
| | | String accessToken = wechatAccessToken.getData().getAccessToken(); |
| | | return accessToken; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 发送消息 |
| | | * @param template_id 所需下发的订阅模板id |
| | |
| | | * @return |
| | | */ |
| | | public R send(String template_id, String page, String touser, String data, String miniprogram_state, String lang){ |
| | | String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + getWxAppletsAccessToken(); |
| | | String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + getToken(false); |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("template_id", template_id); |
| | | params.put("page", page); |
| | |
| | | HttpResponse execute = post.execute(); |
| | | if(execute.getStatus() != 200){ |
| | | log.info("发送消息失败:{}", execute.body()); |
| | | throw new RuntimeException("发送消息失败"); |
| | | return R.fail(execute.body()); |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.body()); |
| | | Integer errcode = jsonObject.getInteger("errcode"); |
| | | if(0 != errcode){ |
| | | log.info("发送消息失败:{}", jsonObject.getString("errmsg")); |
| | | throw new RuntimeException(jsonObject.getString("errmsg")); |
| | | return R.fail(jsonObject.getString("errmsg")); |
| | | } |
| | | return R.ok(); |
| | | } |