浏览代码

Merge branch 'dev' of wujunjie/patient-co-management into dev

trick9191 7 年之前
父节点
当前提交
275de68a50

+ 55 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/common/QrcodeService.java

@ -433,9 +433,9 @@ public class QrcodeService extends BaseService {
    /**
     * 从微信生成二维码并下载到本地
     *
     * @param content
     * @param fileName
     * @param path
     * @param content 场景值
     * @param fileName 二维码文件名
     * @param path 生成二维码路径
     * @param token
     * @throws IOException
     */
@ -500,5 +500,57 @@ public class QrcodeService extends BaseService {
        }
    }
    /**
     * 从微信生成二维码(供第三方调用)
     *
     * @param content
     * @param token
     * @throws IOException
     */
    public String getQrcodeFromWeiXin(String content,String token) throws Exception {
        try {
            String token_url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + token;
            String params = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"" + content + "\"}}}";
            String result = HttpUtil.sendPost(token_url, params);
            if (!StringUtils.isEmpty(result)) {
                JSONObject json = new JSONObject(result);
                if (json.has("ticket")) {
                    // 请求输入流
                    InputStream inputStream = null;
                    // 二维码图片输出流
                    StringBuffer tStringBuffer = new StringBuffer();
                    // 下载二维码图片
                    URL urlGet = new URL("https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="
                            + URLEncoder.encode(json.get("ticket").toString(), "UTF-8"));
                    HttpURLConnection connection = (HttpURLConnection) urlGet.openConnection();
                    connection.connect();
                    inputStream = connection.getInputStream();
                    // 保存图片
                    byte[] data = new byte[1024];
                    int len = 0;
                    while ((len = inputStream.read(data)) != -1) {
                        tStringBuffer.append(data);
                    }
                    if (inputStream != null) {
                        inputStream.close();
                    }
                    return tStringBuffer.toString();
                } else {
                    throw new Exception("请求微信生成二维码失败!");
                }
            } else {
                throw new Exception("请求微信生成二维码失败!");
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new Exception(e.getMessage());
        }
    }
}

+ 15 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/weixin/WeiXinCoreService.java

@ -6,8 +6,12 @@ import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.wechat.process.WeiXinEventProcess;
import com.yihu.wlyy.wechat.util.WeiXinMessageUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -99,4 +103,15 @@ public class WeiXinCoreService extends BaseService {
        return result;
    }
    /**
     * 判断是否是xml结构
     */
    public boolean isXML(String value) {
        try {
            DocumentHelper.parseText(value);
        } catch (DocumentException e) {
            return false;
        }
        return true;
    }
}

+ 59 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/ylzpay/ThirdQrcodeController.java

@ -0,0 +1,59 @@
package com.yihu.wlyy.web.third.ylzpay;
import com.yihu.wlyy.service.app.prescription.PatientPrescriptionPayService;
import com.yihu.wlyy.service.common.QrcodeService;
import com.yihu.wlyy.service.third.jw.JwPrescriptionService;
import com.yihu.wlyy.web.WeixinBaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
/**
 * Created by Reece on 2017/8/30/030.
 * <p>
 * 第三方微信相关事件
 */
@RestController
@RequestMapping(value = "/wlyygc/wechat/")
@Api(description = "供第三方微信类相关业务调用")
public class ThirdQrcodeController extends WeixinBaseController {
    @Value("${server.server_url}")
    private String server_url;
    @Autowired
    private QrcodeService qrcodeService;
    /**
     * 根据场景值获取公众号永久二维码
     *
     * @param scene 场景值
     * @return 返回服务器二维码地址
     * @throws Exception
     */
    @RequestMapping(value = "/getQrcode", method = RequestMethod.POST)
    @ApiOperation(value = "获取公众号二维码接口")
    public String getQrcode(@ApiParam(name = "scene", defaultValue = "") @RequestParam(value = "scene", required = true) String scene) throws Exception {
        try {
            String content = "wechat_" + scene;
            String path = server_url + File.separator + "qrcode";
            // 通过微信接口生成医生二维码
            String result = qrcodeService.makeQrcodeFromWeiXin(content, content.replaceAll("\r\n", ""), path, getAccessToken());
            return write(200, "生成二维码成功!", "data", result);
        } catch (Exception e) {
            e.printStackTrace();
            return write(-1, "生成二维码失败!");
        }
    }
}

+ 16 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/wx/WechatCoreController.java

@ -1,6 +1,7 @@
package com.yihu.wlyy.web.wx;
import com.yihu.wlyy.service.weixin.WeiXinCoreService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.HttpUtil;
import com.yihu.wlyy.web.WeixinBaseController;
import io.swagger.annotations.Api;
@ -39,6 +40,8 @@ public class WechatCoreController extends WeixinBaseController {
    private String appId;
    @Autowired
    private HttpUtil HttpUtil;
    @Autowired
    private PushMsgTask pushMsgTask;
    /**
     * 微信接口验证
@ -83,12 +86,21 @@ public class WechatCoreController extends WeixinBaseController {
            if (validate(signature, timestamp, nonce)) {
                String xmlStr = weiXinCoreService.messageProcess(request, getAccessToken());
                // 判断返回值是xml、json格式(取关是空串)
                Boolean flag = weiXinCoreService.isXML(xmlStr);
                if (xmlStr == "error") {
                    // 服务器错误
                    response.setStatus(500);
                } else if (!flag && StringUtils.isNotEmpty(xmlStr)) {
                    JSONObject json = new JSONObject(xmlStr);
                    if (json.has("openId")) {
                        if (StringUtils.isNotEmpty(json.getString("openId")) && !("undefined".equals(json.getString("openId")))) {
                            pushMsgTask.putWxMsg(getAccessToken(), json.getInt("type"), json.getString("openId"), null, json);
                        }
                    }
                } else {
                    // 返回消息
                    // 返回消息(图文消息)
                    response.getWriter().print(xmlStr);
                }
            } else {
@ -111,7 +123,7 @@ public class WechatCoreController extends WeixinBaseController {
     * @return
     * @throws NoSuchAlgorithmException
     */
    private  boolean validate(String signature, String timestamp, String nonce) throws NoSuchAlgorithmException {
    private boolean validate(String signature, String timestamp, String nonce) throws NoSuchAlgorithmException {
        String token = this.wechat_token;
        // 字典序排序
        String[] array = new String[]{token, timestamp, nonce};
@ -160,7 +172,7 @@ public class WechatCoreController extends WeixinBaseController {
    public String createMenuTest() {
        try {
            String filePath = WechatCoreController.class.getResource("/").getPath() +
                    File.separator + "wechat"+ File.separator+"weixin_menu.txt";
                    File.separator + "wechat" + File.separator + "weixin_menu.txt";
            String url = " https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + getAccessToken();
            // 读取微信菜单配置文件
            InputStreamReader reader = new InputStreamReader(new FileInputStream(filePath), "utf-8");

+ 89 - 51
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/wechat/process/WeiXinEventProcess.java

@ -1,9 +1,12 @@
package com.yihu.wlyy.wechat.process;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.wechat.util.WeiXinMessageReplyUtils;
import com.yihu.wlyy.wechat.util.WeiXinMessageUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@ -23,13 +26,16 @@ public class WeiXinEventProcess {
    private String appId;
    @Value("${server.server_url}")
    private String serverUrl;
    @Autowired
    private PushMsgTask pushMsgTask;
    /**
     * 微信推送事件处理
     *
     * @param message
     * @return
     */
    public  String eventProcess(Map<String, String> message) throws Exception {
    public String eventProcess(Map<String, String> message) throws Exception {
        String result = "";
        String event = message.get("Event");
@ -60,7 +66,7 @@ public class WeiXinEventProcess {
     * @param message
     * @return
     */
    public  String clickProcess(Map<String, String> message) throws Exception {
    public String clickProcess(Map<String, String> message) throws Exception {
        String result = "";
        if (message.get("EventKey").equals("caozuoshuoming")) {
@ -84,7 +90,7 @@ public class WeiXinEventProcess {
     * @return
     * @throws Exception
     */
    private  String clickEventProcess(Map<String, String> message) throws Exception {
    private String clickEventProcess(Map<String, String> message) throws Exception {
        String result = "";
        // 配置信息
        Properties systemConf = SystemConf.getInstance().getSystemProperties();
@ -98,7 +104,7 @@ public class WeiXinEventProcess {
        // 图文消息图片URL
        String picUrlConsult = systemConf.getProperty("patient_operatinginstrutions_pic_url");
        // URL设置服务器URL、AppId
        urlConsult = urlConsult.replace("{server}",wechat_base_url)
        urlConsult = urlConsult.replace("{server}", wechat_base_url)
                .replace("{appId}", appId);
        //图片地址
        picUrlConsult = picUrlConsult.replace("{server}", serverUrl);
@ -134,7 +140,7 @@ public class WeiXinEventProcess {
        // 图文消息图片URL
        String picUrlDevice = systemConf.getProperty("patient_device_pic_url");
        // URL设置服务器URL、AppId
        urlDevice = urlDevice.replace("{server}",wechat_base_url)
        urlDevice = urlDevice.replace("{server}", wechat_base_url)
                .replace("{appId}", appId);
        //图片地址
        picUrlDevice = picUrlDevice.replace("{server}", serverUrl);
@ -153,7 +159,7 @@ public class WeiXinEventProcess {
        String picUrlFamily = systemConf.getProperty("patient_family_pic_url");
        // URL设置服务器URL、AppId
        urlFamily = urlFamily.replace("{server}", wechat_base_url)
                .replace("{appId}",appId);
                .replace("{appId}", appId);
        //图片地址
        picUrlFamily = picUrlFamily.replace("{server}", serverUrl);
@ -178,7 +184,7 @@ public class WeiXinEventProcess {
     * @return
     * @throws Exception
     */
    private  String clickEventProcessMenu(Map<String, String> message) throws Exception {
    private String clickEventProcessMenu(Map<String, String> message) throws Exception {
        String result = "";
        // 配置信息
        Properties systemConf = SystemConf.getInstance().getSystemProperties();
@ -208,8 +214,8 @@ public class WeiXinEventProcess {
        // 图文消息图片URL
        String inspect_pic = systemConf.getProperty("patient_inspect_pic");
        // URL设置服务器URL、AppId
        inspect = inspect.replace("{server}",wechat_base_url)
                .replace("{appId}",appId);
        inspect = inspect.replace("{server}", wechat_base_url)
                .replace("{appId}", appId);
        //图片地址
        inspect_pic = inspect_pic.replace("{server}", serverUrl);
@ -225,10 +231,10 @@ public class WeiXinEventProcess {
        // 图文消息图片URL
        String examination_pic = systemConf.getProperty("patient_examination_pic");
        // URL设置服务器URL、AppId
        examination = examination.replace("{server}",wechat_base_url)
        examination = examination.replace("{server}", wechat_base_url)
                .replace("{appId}", appId);
        //图片地址
        examination_pic = examination_pic.replace("{server}",serverUrl);
        examination_pic = examination_pic.replace("{server}", serverUrl);
        articleExamination.put("Url", examination);
        articleExamination.put("Title", "社区体检");
@ -243,10 +249,10 @@ public class WeiXinEventProcess {
        // 图文消息图片URL
        String prescription_pic = systemConf.getProperty("patient_prescription_pic");
        // URL设置服务器URL、AppId
        prescription = prescription.replace("{server}",wechat_base_url)
                .replace("{appId}",appId);
        prescription = prescription.replace("{server}", wechat_base_url)
                .replace("{appId}", appId);
        //图片地址
        prescription_pic = prescription_pic.replace("{server}",serverUrl);
        prescription_pic = prescription_pic.replace("{server}", serverUrl);
        articlePrescription.put("Url", prescription);
        articlePrescription.put("Title", "处方记录");
@ -280,43 +286,61 @@ public class WeiXinEventProcess {
    /**
     * 关注事件消息发送
     * 关注事件消息构建回复消息体(图文消息xml,模板消息json串)
     *
     * @param message
     * @return
     * @throws Exception
     */
    private  String subscribeEventProcess(Map<String, String> message) throws Exception {
    private String subscribeEventProcess(Map<String, String> message) throws Exception {
        String result = "";
        // 配置信息
        Properties systemConf = SystemConf.getInstance().getSystemProperties();
        // 图文信息
        List<Map<String, String>> articles = new ArrayList<>();
        // 场景值
        String eventKey = message.get("EventKey");
        Map<String, String> article = new HashMap<>();
        // 图文URL
        String url = systemConf.getProperty("doctor_subscribe_url");
        // 图文消息图片URL
        String picUrl = systemConf.getProperty("doctor_qrcode_pic_url");
        // URL设置服务器URL、AppId
        url = url.replace("{server}", wechat_base_url)
                .replace("{appId}", appId);
        //图片地址
        picUrl = picUrl.replace("{server}", serverUrl);
        if (StringUtils.isNotEmpty(eventKey) && (("wechat_ehc").equals(eventKey)) ||
                eventKey.startsWith("qrscene_wechat_ehc")) {
            System.out.println("第三方ehr关注推送事件");
            JSONObject json = new JSONObject();
            json.put("first", "first");
            json.put("remark", "remark");
            json.put("keyword1", "keyword1");
            json.put("keyword2", "keyword2");
            json.put("url", "www.baidu.com");
            //跳转路径问题,如果是第三方不加本地服务器名称(要改push公用方法)
            json.put("openId", message.get("FromUserName"));
            json.put("type", 11);
            //模板消息json串
            result = json.toString();
        } else {
            // 配置信息
            Properties systemConf = SystemConf.getInstance().getSystemProperties();
            // 图文信息
            List<Map<String, String>> articles = new ArrayList<>();
        article.put("Url", url);
        article.put("Title", "欢迎关注厦门i健康,快来签约家庭医生吧~");
        article.put("Description", "请点击查看家庭签约");
        article.put("PicUrl", picUrl);
            Map<String, String> article = new HashMap<>();
            // 图文URL
            String url = systemConf.getProperty("doctor_subscribe_url");
            // 图文消息图片URL
            String picUrl = systemConf.getProperty("doctor_qrcode_pic_url");
            // URL设置服务器URL、AppId
            url = url.replace("{server}", wechat_base_url)
                    .replace("{appId}", appId);
            //图片地址
            picUrl = picUrl.replace("{server}", serverUrl);
        articles.add(article);
            article.put("Url", url);
            article.put("Title", "欢迎关注厦门i健康,快来签约家庭医生吧~");
            article.put("Description", "请点击查看家庭签约");
            article.put("PicUrl", picUrl);
        //设置共有的图文消息
        setUrlItems(articles, systemConf);
            articles.add(article);
        // 构建回复消息XML
        result = WeiXinMessageReplyUtils.replyNewsMessage(message.get("FromUserName"), message.get("ToUserName"), articles);
            //设置共有的图文消息
            setUrlItems(articles, systemConf);
            // 构建回复消息XML
            result = WeiXinMessageReplyUtils.replyNewsMessage(message.get("FromUserName"), message.get("ToUserName"), articles);
        }
        return result;
    }
@ -325,7 +349,7 @@ public class WeiXinEventProcess {
     *
     * @param articles
     */
    public  void setUrlItems(List<Map<String, String>> articles, Properties systemConf) {
    public void setUrlItems(List<Map<String, String>> articles, Properties systemConf) {
        Map<String, String> articleConsult = new HashMap<>();
        // 图文URL
        String urlConsult = systemConf.getProperty("patient_consult_url");
@ -353,7 +377,7 @@ public class WeiXinEventProcess {
        urlBooking = urlBooking.replace("{server}", wechat_base_url)
                .replace("{appId}", appId);
        //图片地址
        picUrlBooking = picUrlBooking.replace("{server}",serverUrl);
        picUrlBooking = picUrlBooking.replace("{server}", serverUrl);
        articleBooking.put("Url", urlBooking);
        articleBooking.put("Title", "预约挂号功能使用说明");
@ -387,9 +411,9 @@ public class WeiXinEventProcess {
        String picUrlFamily = systemConf.getProperty("patient_family_pic_url");
        // URL设置服务器URL、AppId
        urlFamily = urlFamily.replace("{server}", wechat_base_url)
                .replace("{appId}",appId);
                .replace("{appId}", appId);
        //图片地址
        picUrlFamily = picUrlFamily.replace("{server}",serverUrl);
        picUrlFamily = picUrlFamily.replace("{server}", serverUrl);
        articleFamily.put("Url", urlFamily);
        articleFamily.put("Title", "我的家庭功能使用说明");
@ -400,13 +424,13 @@ public class WeiXinEventProcess {
    }
    /**
     * 微信扫码事件处理
     * 微信扫码事件处理(封装图文消息体)
     *
     * @param message
     * @return
     * @throws Exception
     */
    private  String scanEventProcess(Map<String, String> message) throws Exception {
    private String scanEventProcess(Map<String, String> message) throws Exception {
        String result = "";
        // 场景值
        String eventKey = message.get("EventKey");
@ -461,7 +485,7 @@ public class WeiXinEventProcess {
            String[] keys = eventKey.replace("qrscene_hs_", "").replace("hs_", "").split("_");
            // 图文消息URL
            url = url.replace("{server}",wechat_base_url)
            url = url.replace("{server}", wechat_base_url)
                    .replace("{appId}", appId)
                    .replace("{hospital}", keys[0] + ":" + keys[1]);
            //图片地址
@ -496,7 +520,7 @@ public class WeiXinEventProcess {
            // 图文消息URL
            url = url.replace("{server}", wechat_base_url)
                    .replace("{appId}",appId)
                    .replace("{appId}", appId)
                    .replace("{town}", keys[0]);
            //图片地址
            picUrl = picUrl.replace("{server}", serverUrl);
@ -514,6 +538,20 @@ public class WeiXinEventProcess {
            articles.add(videoText);
            // 消息XML
            result = WeiXinMessageReplyUtils.replyNewsMessage(message.get("FromUserName"), message.get("ToUserName"), articles);
        } else if (StringUtils.isNotEmpty(eventKey) && (("wechat_ehc").equals(eventKey)) ||
                eventKey.startsWith("qrscene_wechat_ehc")) {
            System.out.println("第三方ehr扫描推送事件");
            JSONObject json = new JSONObject();
            json.put("first", "first");
            json.put("remark", "remark");
            json.put("keyword1", "keyword1");
            json.put("keyword2", "keyword2");
            json.put("url", "www.baidu.com");
            //跳转路径问题,如果是第三方不加本地服务器名称(要改push公用方法)
            json.put("openId", message.get("FromUserName"));
            json.put("type", 11);
            //模板消息json串
            result = json.toString();
        }
        return result;
@ -528,7 +566,7 @@ public class WeiXinEventProcess {
     * @param description 图文描述
     * @return
     */
    public  Map getNews(String url, String picUrl, String title, String description) {
    public Map getNews(String url, String picUrl, String title, String description) {
        Properties systemConf = SystemConf.getInstance().getSystemProperties();
        Map<String, String> news = new HashMap<>();
        // 图文URL
@ -536,8 +574,8 @@ public class WeiXinEventProcess {
        // 图文消息图片URL
        String pictureUrl = systemConf.getProperty(picUrl);
        // URL设置服务器URL、AppId
        targetUrl = targetUrl.replace("{server}",wechat_base_url)
                .replace("{appId}",appId);
        targetUrl = targetUrl.replace("{server}", wechat_base_url)
                .replace("{appId}", appId);
        //图片地址
        pictureUrl = pictureUrl.replace("{server}", serverUrl);
        System.out.println("url ====> " + targetUrl);
@ -559,7 +597,7 @@ public class WeiXinEventProcess {
     * @param message
     * @return
     */
    public  String replyKeyword(Map<String, String> message) throws Exception {
    public String replyKeyword(Map<String, String> message) throws Exception {
        String result = "";
        String description = "您的家庭医生签约将于6月30日到期,为了能继续给您提供健康服务,诚邀您续签家庭医生。";
        String description1 = "为了能给您提供健康服务,诚邀您签签约家庭医生。";