| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.dg.core.annotation.Authorization; |
| | | import com.dg.core.db.gen.entity.GuideEvolveEntity; |
| | | import com.dg.core.db.gen.entity.GuideRepairOrder; |
| | | import com.dg.core.db.gen.entity.SysUser; |
| | | import com.dg.core.db.manual.mapper.util.ConstantPropertiesUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | import org.apache.http.client.methods.HttpPost; |
| | | import org.apache.http.entity.StringEntity; |
| | | import org.apache.http.impl.client.DefaultHttpClient; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | |
| | | |
| | | private static String ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential"; |
| | | |
| | | private static String miniprogramState="trial";//trial 为测试版 formal 为正式版 切记发布版本时候改为正式版 |
| | | |
| | | @Resource(name = "stringRedisTemplate") |
| | | private StringRedisTemplate stringRedisTemplate; |
| | | |
| | | private static WxUtil wxUtil; |
| | | |
| | | @PostConstruct |
| | | public void init() { |
| | | wxUtil = this; |
| | | wxUtil.stringRedisTemplate = this.stringRedisTemplate; |
| | | } |
| | | |
| | | /** |
| | | * 获取花城token,(ps:0=token获取失败) |
| | | * |
| | |
| | | */ |
| | | public String getBatteryCarAccessToken() throws Exception { |
| | | String accessToken = "0"; |
| | | try { |
| | | // 此处APP_ID APP_SECRET 在微信小程序后端可见 |
| | | // String accessTokenUrl = String.format(TEMP_URL, APP_ID, APP_SECRET); |
| | | String accessTokenUrl = ACCESS_TOKEN_URL + "&appid=" + ConstantPropertiesUtil.WX_OPEN_APP_ID |
| | | + "&secret=" +ConstantPropertiesUtil.WX_OPEN_APP_SECRET; |
| | | String result = httpGet(accessTokenUrl, null, null); |
| | | Map<String, Object> resultMap = JSON.parseObject(result, Map.class); |
| | | if (resultMap.containsKey("access_token")) { |
| | | accessToken = resultMap.get("access_token").toString(); |
| | | } |
| | | } catch (IOException ioe) { |
| | | ioe.printStackTrace(); |
| | | } |
| | | // try { |
| | | // // 此处APP_ID APP_SECRET 在微信小程序后端可见 |
| | | // // String accessTokenUrl = String.format(TEMP_URL, APP_ID, APP_SECRET); |
| | | // String accessTokenUrl = ACCESS_TOKEN_URL + "&appid=" + ConstantPropertiesUtil.WX_OPEN_APP_ID |
| | | // + "&secret=" +ConstantPropertiesUtil.WX_OPEN_APP_SECRET; |
| | | // String result = httpGet(accessTokenUrl, null, null); |
| | | // Map<String, Object> resultMap = JSON.parseObject(result, Map.class); |
| | | // if (resultMap.containsKey("access_token")) { |
| | | // accessToken = resultMap.get("access_token").toString(); |
| | | // } |
| | | // } catch (IOException ioe) { |
| | | // ioe.printStackTrace(); |
| | | // } |
| | | accessToken =wxUtil.stringRedisTemplate.boundValueOps("access_token:access_token:" + ConstantPropertiesUtil.WX_OPEN_APP_ID).get(); |
| | | return accessToken; |
| | | } |
| | | |
| | |
| | | WxSubscribeDTO subscribeDTO = new WxSubscribeDTO(); |
| | | subscribeDTO.setTouser(openId); |
| | | subscribeDTO.setTemplate_id(templateId); |
| | | subscribeDTO.setMiniprogram_state("formal");//测试,部署正式版本时候需要更改为formal |
| | | subscribeDTO.setMiniprogram_state(miniprogramState); |
| | | subscribeDTO.setPage("packageE/pages/myApply/myApply"); |
| | | List<TemplateParam> paras=new ArrayList<TemplateParam>(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | paras.add(new TemplateParam("thing1","导办申请"));//业务办理类型 |
| | |
| | | WxSubscribeDTO subscribeDTO = new WxSubscribeDTO(); |
| | | subscribeDTO.setTouser(openId); |
| | | subscribeDTO.setTemplate_id(templateId); |
| | | subscribeDTO.setMiniprogram_state("formal");//测试,部署正式版本时候需要更改为formal |
| | | subscribeDTO.setMiniprogram_state(miniprogramState); |
| | | subscribeDTO.setPage("packageE/pages/applyHandle/index/index"); |
| | | List<TemplateParam> paras=new ArrayList<TemplateParam>(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | paras.add(new TemplateParam("thing4","您有一个新的导办工单需要处理"));//超时提示内容 |
| | | paras.add(new TemplateParam("thing4","您有一个新的导办工单需要处理"));//工单新增提示内容 |
| | | paras.add(new TemplateParam("thing2",guideRepairOrder.getConsultUserName()));//咨询人 |
| | | paras.add(new TemplateParam("thing3",guideRepairOrder.getConsultContent()));//咨询内容 |
| | | subscribeDTO.setTemplateParamList(paras); |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 工单超时推送 |
| | | * |
| | | * @param openId |
| | | * 用户openid |
| | | * @param accessToken |
| | | * token会话标识 |
| | | */ |
| | | public void sendGuideRepairOrderOvertime(String openId, String accessToken, String templateId, SysUser sysUser){ |
| | | WxSubscribeDTO subscribeDTO = new WxSubscribeDTO(); |
| | | subscribeDTO.setTouser(openId); |
| | | subscribeDTO.setTemplate_id(templateId); |
| | | subscribeDTO.setMiniprogram_state(miniprogramState); |
| | | subscribeDTO.setPage("packageE/pages/applyHandle/index/index"); |
| | | List<TemplateParam> paras=new ArrayList<TemplateParam>(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(new Date()); |
| | | paras.add(new TemplateParam("time1",calendar.get(Calendar.YEAR)+"年"+(calendar.get(Calendar.MONTH)+1)+"月"+calendar.get(Calendar.DATE)+"日"));//超时时间 |
| | | paras.add(new TemplateParam("thing2",sysUser.getUserName()+"导办人员有个工单已超时"));//咨询人 |
| | | subscribeDTO.setTemplateParamList(paras); |
| | | try { |
| | | sendSubscribe(accessToken,subscribeDTO); |
| | | }catch (Exception e){ |
| | | System.out.println(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | } |