trick9191 7 年之前
父节点
当前提交
fb385e5a7b

+ 6 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/weixin/applets/AppletsService.java

@ -52,6 +52,7 @@ public class AppletsService extends BaseService {
        Map<String, Object> res = new HashedMap();
        res.put("openid", rs.getString("openid"));
        res.put("sessionKey", rs.getString("session_key"));
        res.put("unionid", rs.getString("unionid"));
        return res;
    }
@ -138,10 +139,11 @@ public class AppletsService extends BaseService {
    public Map<String,Object> getPatientByUid(String unionid){
        Patient patient = patientDao.findByUnionid(unionid);
        Map<String,Object> map = new HashedMap();
        map.put("patient",patient.getCode());
        map.put("patientName",patient.getName());
        map.put("photo",patient.getPhoto());
        if(patient!=null){
            map.put("patient",patient.getCode());
            map.put("patientName",patient.getName());
            map.put("photo",patient.getPhoto());
        }
        return map;
    }

+ 25 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/WeixinBaseController.java

@ -71,6 +71,31 @@ public class WeixinBaseController extends BaseController {
		return null;
	}
	/**
	 * 通过code获取判断openid
	 *
	 * @param code
	 * @return
	 */
	public String getUnionIDByCode(String code) {
		try {
			String token_url = "https://api.weixin.qq.com/sns/oauth2/access_token";
			String params = "appid=" + appId + "&secret=" +appSecret+ "&code=" + code + "&grant_type=authorization_code";
			String result = HttpUtil.sendGet(token_url, params);
			System.out.println("getOpenidByCode:"+result);
			JSONObject json = new JSONObject(result);
			System.out.println("result:"+json.toString());
			if (json.has("unionid")) {
				return json.get("unionid").toString();
			} else {
				return null;
			}
		} catch (Exception e) {
			error(e);
		}
		return null;
	}
	/**
	 * 通过code获取判断openid
	 * 

+ 22 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/account/WechatController.java

@ -682,5 +682,27 @@ public class WechatController extends WeixinBaseController {
        }
    }
    /**
     * 获取微信unionid
     *
     * @param code
     * @return
     */
    @RequestMapping(value = "getUnionidByCode", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public String getUnionidByCode(String code) {
        try {
            String unionid = super.getOpenidByCode(code);
            if (!StringUtils.isEmpty(unionid)) {
                return write(200, "获取unionid成功!", "unionid", unionid);
            } else {
                return error(-1, "获取unionid失败!");
            }
        } catch (Exception e) {
            error(e);
            return error(-1, "获取unionid失败!");
        }
    }
}