|
@@ -6,11 +6,15 @@ import com.szwl.model.bo.R;
|
|
|
import com.szwl.model.entity.TSzsmWx;
|
|
|
import com.szwl.mapper.TSzsmWxMapper;
|
|
|
import com.szwl.model.utils.HttpClientSslUtils;
|
|
|
+import com.szwl.model.utils.JsonUtil;
|
|
|
import com.szwl.service.TSzsmWxService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 服务实现类
|
|
@@ -46,4 +50,47 @@ public class TSzsmWxServiceImpl extends ServiceImpl<TSzsmWxMapper, TSzsmWx> impl
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String subscribeMessage(Long id,String code,String clientId) {
|
|
|
+ if(id==null){
|
|
|
+ return "error";
|
|
|
+ }
|
|
|
+ TSzsmWx szsmWx = getById(id);
|
|
|
+ //1,获取获取token
|
|
|
+ String accessToken =null;
|
|
|
+ TSzsmWx wx = getById(1);
|
|
|
+ accessToken = wx.getAvatarUrl();
|
|
|
+ String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="+accessToken;
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("template_id", "NVmdaK4MwygT63ME830pwM6wZt4eufxhBr6jlQ2XXJ4");
|
|
|
+ jsonObject.put("touser", szsmWx.getOpenId());
|
|
|
+ Map<String,String> map = new HashMap<>();
|
|
|
+ //取货码 code
|
|
|
+ map.put("character_string1",code);
|
|
|
+ //取货点 clientId
|
|
|
+ map.put("thing2",clientId);
|
|
|
+ //温馨提示
|
|
|
+ map.put("thing5","");
|
|
|
+ jsonObject.put("data", map);
|
|
|
+ jsonObject.put("miniprogram_state","formal");
|
|
|
+ jsonObject.put("lang","zh_CN");
|
|
|
+ String reqJsonStr = JsonUtil.objToString(jsonObject);
|
|
|
+ JSONObject result = null;
|
|
|
+ try {
|
|
|
+ result = JSON.parseObject(HttpClientSslUtils.doPost(url, reqJsonStr));
|
|
|
+ if (result != null) {
|
|
|
+ String errmsg = result.getString("errmsg");
|
|
|
+ if(errmsg.equals("ok")){
|
|
|
+ szsmWx.setIfSubscribe("0");
|
|
|
+ updateById(szsmWx);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|