| 
					
				 | 
			
			
				@ -47,12 +47,13 @@ import com.yihu.jw.util.date.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.wechat.WeiXinPayUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.wechat.wxhttp.HttpUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.utils.ByteToInputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.utils.StringUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.wechat.dao.BasePatientWechatDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.wechat.dao.WechatDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.wechat.dao.WxPayLogDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.wechat.enterprise.EnterpriseService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.mysql.query.BaseJpaService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.utils.network.HttpResponse; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.utils.network.HttpUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.collections.map.HashedMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.Logger; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -385,7 +386,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String appCallBack = businessOrderDO.getAppCallbackUrl(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String url = wxWechatDO.getBaseUrl(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String notifyUrl =url; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String,Object> map = unifiedorder(wechatId,description,businessOrderDO.getPayPrice().toString(),WeChatConfig.TRADE_TYPE_JSAPI,openId,orderNo,notifyUrl); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String,Object> map = unifiedorder(wechatId,description,businessOrderDO.getPayPrice().toString(),WeChatConfig.TRADE_TYPE_JSAPI,openId,orderNo,notifyUrl,patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String doctorId = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (doctorMappingDO!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            doctorId = doctorMappingDO.getMappingCode(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -433,30 +434,57 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return HttpUtil.doRefund("https://api.mch.weixin.qq.com/secapi/pay/refund",xml,hospitalSysDictDO.getDictCode(),hospitalSysDictDO.getDictValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Map<String,Object> selectOrderByRelationCode(String relationCode,String tradeType,String wechatId,boolean payFlag) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Map<String, Object> checkApplets(String code,String appid,String appSecret) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        HttpUtils httpUtils = new HttpUtils(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String, Object> param = new HashedMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        param.put("appid", appid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        param.put("secret", appSecret); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        param.put("js_code", code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        param.put("grant_type", "authorization_code"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        HttpResponse response = httpUtils.doGet("https://api.weixin.qq.com/sns/jscode2session", param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        org.json.JSONObject rs = new org.json.JSONObject(response.getContent()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String, Object> res = new HashedMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logger.info("checkApplets:"+response.getContent()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (rs.has("openid")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            res.put("openid", rs.getString("openid")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            res.put("sessionKey", rs.getString("session_key")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return res; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Map<String,Object> selectOrderByRelationCode(String relationCode,String tradeType,String wechatId,boolean payFlag,String appletCode) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        WxWechatDO wxWechatDO = wechatDao.findById(wechatId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(relationCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String body = businessOrderDO.getDescription(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String totalFee = businessOrderDO.getPayPrice().intValue()+""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String patient = businessOrderDO.getPatient(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String openid = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isNoneBlank(patient)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<BasePatientWechatDo> patientWechatDo = patientWechatDao.findByWechatIdAndPatientId(wechatId,patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (patientWechatDo!=null&&patientWechatDo.size()!=0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                openid = patientWechatDo.get(0).getOpenid(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isNotBlank(appletCode)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logger.info("appletCode不为空"+appletCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map<String,Object> objectMap = checkApplets(appletCode,wxWechatDO.getApplets(),wxWechatDO.getAppletsSecret()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (objectMap!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                openid = objectMap.get("openid").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                logger.info("appletCode"+appletCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                logger.info("openid"+openid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logger.info("appletCode为空"+appletCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (StringUtils.isNoneBlank(patient)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<BasePatientWechatDo> patientWechatDo = patientWechatDao.findByWechatIdAndPatientId(wechatId,patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (patientWechatDo!=null&&patientWechatDo.size()!=0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    openid = patientWechatDo.get(0).getOpenid(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String ourTradeNo = businessOrderDO.getOrderNo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (!StringUtils.isNoneBlank(tradeType)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            tradeType=WeChatConfig.TRADE_TYPE_JSAPI; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String url = wxWechatDO.getBaseUrl(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String notifyUrl =url; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String,Object> map = new HashedMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (payFlag){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map = unifiedorder(wechatId,body,totalFee,tradeType,openid,ourTradeNo,notifyUrl); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map = unifiedorder(wechatId,body,totalFee,tradeType,openid,ourTradeNo,notifyUrl,patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            updatePayStatusByRelation(relationCode,wechatId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -475,7 +503,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public  Map<String,Object> unifiedorder(String wechatId,String body,String totalFee,String tradeType,String openId,String ourTradeNo,String notifyUrl) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public  Map<String,Object> unifiedorder(String wechatId,String body,String totalFee,String tradeType,String openId,String ourTradeNo,String notifyUrl,String code) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        WxWechatDO wxWechatDO = wechatDao.findById(wechatId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(wxWechatDO==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new Exception("can't find wechat:the wxId is "+wechatId); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -498,7 +526,14 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new Exception("ourTradeNo is null :the ourTradeNo is "+ourTradeNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        HashMap<String, String> map = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        map.put("appid",wxWechatDO.getAppId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (tradeType.equalsIgnoreCase("APPLETS")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("appid",wxWechatDO.getApplets()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("trade_type", "JSAPI"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("appid",wxWechatDO.getAppId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("trade_type", tradeType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        map.put("mch_id",wxWechatDO.getMchId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        map.put("body",body); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        map.put("out_trade_no",ourTradeNo); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -506,10 +541,17 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        map.put("total_fee",totalFee); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        map.put("spbill_create_ip",getServerIp()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        map.put("notify_url",notifyUrl); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        map.put("trade_type", tradeType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (tradeType.equalsIgnoreCase("JSAPI")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("openid", openId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (tradeType.equalsIgnoreCase("APPLETS")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            /*BasePatientDO patientDO = patientDao.findById(code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (patientDO!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                map.put("openid",patientDO.getOpenid()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("openid", openId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String wapUrl = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String wapName = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if ("xm_ykyy_wx".equalsIgnoreCase(wechatId)){ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -789,6 +831,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        wlyyOutpatientDO.setPayStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        outpatientDao.save(wlyyOutpatientDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }else if (businessOrderDO.getOrderCategory().equalsIgnoreCase("2")||businessOrderDO.getOrderCategory().equalsIgnoreCase("3")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(businessOrderDO.getRelationCode()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -881,11 +924,11 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            wxPayLogDO.setPayTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            wxPayLogDO.setPayStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            wxPayLogDao.save(wxPayLogDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            rs.put("code","1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            rs.put("message","支付成功"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            rs.put("return_code","SUCCESS"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            rs.put("return_msg","OK"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            rs.put("code","-1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            rs.put("return_msg","FAIL"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            rs.put("return_code","FAIL"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            rs.put("return_msg","OK"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return rs; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -1660,9 +1703,10 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String url = wxWechatDO.getBaseUrl(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String notifyUrl =url; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String price = (int)(businessOrderDO.getPayPrice()*100)+""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        map = unifiedorder(wechatId,businessOrderDO.getDescription(),price,wxPayType,patientWechatDoList.get(0).getOpenid(),businessOrderDO.getOrderNo(),notifyUrl); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        map = unifiedorder(wechatId,businessOrderDO.getDescription(),price,wxPayType,patientWechatDoList.get(0).getOpenid(),businessOrderDO.getOrderNo(),notifyUrl,patientId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logger.info("success="+JSONObject.toJSONString(map)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |