|
|
@@ -19,7 +19,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import com.dk.mdm.service.mst.CusFollowService;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.PrintWriter;
|
|
|
+import java.security.MessageDigest;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -132,4 +138,62 @@ public class CusFollowController{
|
|
|
public ResponseResultVO<?> testPush() {
|
|
|
return cusFollowService.customerReminder();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "小程序消息推送测试", notes = "小程序消息推送测试")
|
|
|
+ @GetMapping("wx_message_test")
|
|
|
+ @ResponseBody
|
|
|
+ public void wxMessageTest(HttpServletRequest request, HttpServletResponse response){
|
|
|
+ String signature = request.getParameter("signature");
|
|
|
+ String timestamp = request.getParameter("timestamp");
|
|
|
+
|
|
|
+ String nonce = request.getParameter("nonce");
|
|
|
+
|
|
|
+ String echostr = request.getParameter("echostr");
|
|
|
+ // 和小程序后台配置的token保持一致
|
|
|
+ String token = "dPM4EILWQqeEsEmft9pKMIll4VGZ6pJK";
|
|
|
+ // 将下面三个参数拼接成字符串
|
|
|
+ StringBuffer content = new StringBuffer();
|
|
|
+ content.append(timestamp);
|
|
|
+ content.append(nonce);
|
|
|
+ content.append(token);
|
|
|
+ PrintWriter out = null;
|
|
|
+ try {
|
|
|
+ out = response.getWriter();
|
|
|
+ MessageDigest md = MessageDigest.getInstance("SHA-1");
|
|
|
+ // 对拼接好的字符串进行sha1加密
|
|
|
+ byte[] digest = md.digest(content.toString().getBytes());
|
|
|
+ String tmpStr = byteToStr(digest);
|
|
|
+ //获得加密后的字符串与signature对比
|
|
|
+ if (tmpStr != null && tmpStr.equals(signature.toUpperCase())){
|
|
|
+ out.print(echostr);
|
|
|
+ out.flush();
|
|
|
+ }
|
|
|
+ } catch (NoSuchAlgorithmException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ out.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String byteToStr(byte[] byteArray) {
|
|
|
+ String strDigest = "";
|
|
|
+ for (int i = 0; i < byteArray.length; i++) {
|
|
|
+ strDigest += byteToHexStr(byteArray[i]);
|
|
|
+ }
|
|
|
+ return strDigest;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String byteToHexStr(byte mByte) {
|
|
|
+ char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A',
|
|
|
+ 'B', 'C', 'D', 'E', 'F' };
|
|
|
+ char[] tempArr = new char[2];
|
|
|
+ tempArr[0] = Digit[(mByte >>> 4) & 0X0F];
|
|
|
+ tempArr[1] = Digit[mByte & 0X0F];
|
|
|
+ String s = new String(tempArr);
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+
|
|
|
}
|