You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					
					
						
							117 lines
						
					
					
						
							4.5 KiB
						
					
					
				
			
		
		
	
	
							117 lines
						
					
					
						
							4.5 KiB
						
					
					
				| package com.ynxbd.wx.wxfactory.medical;
 | |
| 
 | |
| import com.ynxbd.common.helper.ProperHelper;
 | |
| import com.ynxbd.wx.config.WeChatConfig;
 | |
| 
 | |
| import javax.crypto.Mac;
 | |
| import javax.crypto.spec.SecretKeySpec;
 | |
| import java.io.UnsupportedEncodingException;
 | |
| import java.net.URLEncoder;
 | |
| import java.nio.charset.StandardCharsets;
 | |
| 
 | |
| public class MdConfig {
 | |
|     private MdConfig() {
 | |
|     }
 | |
| 
 | |
|     // 免密授权
 | |
|     final private static char[] HEX_ARRAY = "0123456789abcdef".toCharArray();
 | |
| 
 | |
|     //配置文件读取项
 | |
|     public static final boolean IS_ENABLE;
 | |
|     public static final String CITY_CODE; // 城市编码
 | |
|     public static final String CHANNEL;
 | |
|     public static final String ORG_CHNL_CRTF_CODG;
 | |
|     public static final String ORG_NO;
 | |
|     public static final String ORG_APP_ID;
 | |
|     public static final String PAY_KEY;
 | |
|     public static final String HOSPITAL_NAME;
 | |
|     // 免密授权
 | |
|     public static final String PARTNER_ID;
 | |
|     public static final String PARTNER_SECRET;
 | |
|     public static final String PARTNER_URL;
 | |
| 
 | |
|     public static final String MD_APP_ID;
 | |
|     public static final String MD_APP_SECRET;
 | |
| 
 | |
|     public static boolean IS_DEV = true;
 | |
| 
 | |
|     static {
 | |
|         ProperHelper config = new ProperHelper().read("medical.properties");
 | |
| 
 | |
|         IS_ENABLE = config.getBoolean("medical.is_enable", false);
 | |
|         config.setIsEnable(IS_ENABLE);
 | |
| 
 | |
|         IS_DEV = config.getBoolean("medical.is_dev", true);
 | |
|         CHANNEL = config.getString("medical.channel");
 | |
|         ORG_NO = config.getString("medical.org_no");
 | |
|         ORG_APP_ID = config.getString("medical.org_app_id");
 | |
|         ORG_CHNL_CRTF_CODG = config.getString("medical.org_chnl_crtf_codg");
 | |
|         PAY_KEY = config.getString("medical.pay_key");
 | |
|         CITY_CODE = config.getString("medical.city_code");
 | |
|         HOSPITAL_NAME = config.getString("medical.hospital_name");
 | |
|         // 免密授权
 | |
|         PARTNER_ID = config.getString("medical.partner_id");
 | |
|         // 服务号appId
 | |
|         MD_APP_ID = config.getString("medical.md_app_id", WeChatConfig.APP_ID);
 | |
|         MD_APP_SECRET = config.getString("medical.md_app_secret", WeChatConfig.APP_SECRET);
 | |
| 
 | |
|         PARTNER_SECRET = IS_DEV ?
 | |
|                 config.getString("medical.dev_partner_secret") :
 | |
|                 config.getString("medical.partner_secret");
 | |
| 
 | |
|         PARTNER_URL = IS_DEV ?
 | |
|                 "https://med-biz-pre.wecity.qq.com/api/mipuserquery/userQuery/" + PARTNER_ID :
 | |
|                 "https://med-biz.wecity.qq.com/api/mipuserquery/userQuery/" + PARTNER_ID;
 | |
| 
 | |
|     }
 | |
| 
 | |
|     protected static String getConfigUrl(String returnUrl) {
 | |
|         try {
 | |
|             String url = IS_DEV ? "https://mitest.wecity.qq.com" : "https://card.wecity.qq.com";
 | |
| 
 | |
|             return String.format(url + "/openAuth/info?authType=2&isDepart=2&appid=%s&cityCode=%s&channel=%s&bizType=04107&orgCodg=%s&orgAppId=%s&orgChnlCrtfCodg=%s&redirectUrl=%s",
 | |
|                     MD_APP_ID,
 | |
|                     CITY_CODE,
 | |
|                     CHANNEL,
 | |
|                     ORG_NO,
 | |
|                     ORG_APP_ID,
 | |
|                     URLEncoder.encode(ORG_CHNL_CRTF_CODG, String.valueOf(StandardCharsets.UTF_8)),
 | |
|                     returnUrl);
 | |
|         } catch (Exception e) {
 | |
|             e.printStackTrace();
 | |
|         }
 | |
|         return null;
 | |
|     }
 | |
| 
 | |
| 
 | |
|     private static String bytesToHex(byte[] bytes) {
 | |
|         char[] hexChars = new char[bytes.length * 2];
 | |
|         for (int j = 0; j < bytes.length; j++) {
 | |
|             int v = bytes[j] & 0Xff;
 | |
|             hexChars[j * 2] = HEX_ARRAY[v >>> 4];
 | |
|             hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
 | |
|         }
 | |
|         return new String(hexChars);
 | |
|     }
 | |
| 
 | |
|     public static String createSignature(String timestamp) {
 | |
|         try {
 | |
|             Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
 | |
|             SecretKeySpec secret_key = new SecretKeySpec(PARTNER_SECRET.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
 | |
|             sha256_HMAC.init(secret_key);
 | |
|             return bytesToHex(sha256_HMAC.doFinal((PARTNER_ID + timestamp).getBytes(StandardCharsets.UTF_8)));
 | |
|         } catch (Exception e) {
 | |
|             e.printStackTrace();
 | |
|         }
 | |
|         return null;
 | |
|     }
 | |
| 
 | |
|     public static void main(String[] args) throws UnsupportedEncodingException {
 | |
|         String encode = URLEncoder.encode("+", String.valueOf(StandardCharsets.UTF_8));
 | |
|         System.out.println(encode);
 | |
|     }
 | |
| 
 | |
| //    public static void main(String[] args) {
 | |
| //        System.out.println(getAuthUrl("http://wx.hhzyy.com/wx/web/wx-yb02.html"));
 | |
| //    }
 | |
| }
 | |
| 
 |