刘韬 3 years ago
parent
commit
1159585424

+ 89 - 89
PacsOnline_Wechat_Patient/src/main/java/com/zskk/controller/WeixinPayController.java

@@ -30,8 +30,8 @@ public class WeixinPayController extends Controller {
 	 * 公众号支付js-sdk
 	 */
 	public void index() {
-//		String institution_id = this.getPara("institution_id");
-//		if (institution_id == null || !institution_id.equals("03060002")) {
+		String institution_id = this.getPara("institution_id");
+		if (institution_id == null || !institution_id.equals("03060002")) {
 			String out_trade_no = this.getPara("out_trade_no");
 			if (out_trade_no == null) {
 				renderText("need out_trade_no");
@@ -118,94 +118,94 @@ public class WeixinPayController extends Controller {
 			System.out.println(jsonStr);
 //        renderJson("{\"code\":0}");
 			renderText(jsonStr);
-//		} else if (institution_id.equals("03060002")) {
-//			String out_trade_no = this.getPara("out_trade_no");
-//			if (out_trade_no == null) {
-//				renderText("need out_trade_no");
-//			}
-////			String appId = this.getPara("appId");
-////			if (appId == null) {
-////				renderText("need appId");
-////			}
-//			String openid = this.getPara("openid");
-//			if (openid == null) {
-//				renderText("need openid");
-//			}
-//			String body = this.getPara("body");
-//			if (body == null) {
-//				renderText("need body");
-//			}
-//			String total_fee = this.getPara("total_fee");
-//			if (total_fee == null) {
-//				renderText("need total_fee");
-//			}
-//			String notify_url = this.getPara("notify_url");
-//			if (notify_url == null) {
-//				renderText("need notify_url");
-//			}
-//
-//			ApiConfigKit.setThreadLocalAppId(appid);
-//
-//			// 统一下单文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1
-//
-//			Map<String, String> params = new HashMap<String, String>();
-//			params.put("appid", appid);
-//			params.put("mch_id", partner_jx);
-//			params.put("body", body);
-//			params.put("out_trade_no", out_trade_no);
-//			params.put("total_fee", total_fee);
-//
-//			String ip = IpKit.getRealIp(getRequest());
-//			if (StrKit.isBlank(ip)) {
-//				ip = "127.0.0.1";
-//			}
-//			if (ip.contains(",")) {
-//				ip = ip.split(",")[0];
-//			}
-//
-//			params.put("spbill_create_ip", ip);
-//			params.put("trade_type", TradeType.JSAPI.name());
-//			params.put("nonce_str", System.currentTimeMillis() / 1000 + "");
-//			params.put("notify_url", notify_url);
-//			params.put("openid", openid);
-//
-//			String sign = PaymentKit.createSign(params, paternerKey_jx);
-//			params.put("sign", sign);
-//			String xmlResult = PaymentApi.pushOrder(params);
-//
-//			System.out.println(xmlResult);
-//
-//			Map<String, String> result = PaymentKit.xmlToMap(xmlResult);
-//
-//			String return_code = result.get("return_code");
-//			String return_msg = result.get("return_msg");
-//			if (StrKit.isBlank(return_code) || !"SUCCESS".equals(return_code)) {
-//				renderText(xmlResult);
-//				return;
-//			}
-//			String result_code = result.get("result_code");
-//			if (StrKit.isBlank(result_code) || !"SUCCESS".equals(result_code)) {
-//				renderText(xmlResult);
-//				return;
+		} else if (institution_id.equals("03060002")) {
+			String out_trade_no = this.getPara("out_trade_no");
+			if (out_trade_no == null) {
+				renderText("need out_trade_no");
+			}
+//			String appId = this.getPara("appId");
+//			if (appId == null) {
+//				renderText("need appId");
 //			}
-//			// 以下字段在return_code 和result_code都为SUCCESS的时候有返回
-//			String prepay_id = result.get("prepay_id");
-//
-//			Map<String, String> packageParams = new HashMap<String, String>();
-//			packageParams.put("appId", appid);
-//			packageParams.put("timeStamp", System.currentTimeMillis() / 1000 + "");
-//			packageParams.put("nonceStr", System.currentTimeMillis() + "");
-//			packageParams.put("package", "prepay_id=" + prepay_id);
-//			packageParams.put("signType", "MD5");
-//			String packageSign = PaymentKit.createSign(packageParams, paternerKey_jx);
-//			packageParams.put("paySign", packageSign);
-//
-//			String jsonStr = JsonUtils.toJson(packageParams);
-//			setAttr("json", jsonStr);
-//			System.out.println(jsonStr);
-////	        renderJson("{\"code\":0}");
-//			renderText(jsonStr);
-//		}
+			String openid = this.getPara("openid");
+			if (openid == null) {
+				renderText("need openid");
+			}
+			String body = this.getPara("body");
+			if (body == null) {
+				renderText("need body");
+			}
+			String total_fee = this.getPara("total_fee");
+			if (total_fee == null) {
+				renderText("need total_fee");
+			}
+			String notify_url = this.getPara("notify_url");
+			if (notify_url == null) {
+				renderText("need notify_url");
+			}
+
+			ApiConfigKit.setThreadLocalAppId(appid);
+
+			// 统一下单文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1
+
+			Map<String, String> params = new HashMap<String, String>();
+			params.put("appid", appid);
+			params.put("mch_id", partner_jx);
+			params.put("body", body);
+			params.put("out_trade_no", out_trade_no);
+			params.put("total_fee", total_fee);
+
+			String ip = IpKit.getRealIp(getRequest());
+			if (StrKit.isBlank(ip)) {
+				ip = "127.0.0.1";
+			}
+			if (ip.contains(",")) {
+				ip = ip.split(",")[0];
+			}
+
+			params.put("spbill_create_ip", ip);
+			params.put("trade_type", TradeType.JSAPI.name());
+			params.put("nonce_str", System.currentTimeMillis() / 1000 + "");
+			params.put("notify_url", notify_url);
+			params.put("openid", openid);
+
+			String sign = PaymentKit.createSign(params, paternerKey_jx);
+			params.put("sign", sign);
+			String xmlResult = PaymentApi.pushOrder(params);
+
+			System.out.println(xmlResult);
+
+			Map<String, String> result = PaymentKit.xmlToMap(xmlResult);
+
+			String return_code = result.get("return_code");
+			String return_msg = result.get("return_msg");
+			if (StrKit.isBlank(return_code) || !"SUCCESS".equals(return_code)) {
+				renderText(xmlResult);
+				return;
+			}
+			String result_code = result.get("result_code");
+			if (StrKit.isBlank(result_code) || !"SUCCESS".equals(result_code)) {
+				renderText(xmlResult);
+				return;
+			}
+			// 以下字段在return_code 和result_code都为SUCCESS的时候有返回
+			String prepay_id = result.get("prepay_id");
+
+			Map<String, String> packageParams = new HashMap<String, String>();
+			packageParams.put("appId", appid);
+			packageParams.put("timeStamp", System.currentTimeMillis() / 1000 + "");
+			packageParams.put("nonceStr", System.currentTimeMillis() + "");
+			packageParams.put("package", "prepay_id=" + prepay_id);
+			packageParams.put("signType", "MD5");
+			String packageSign = PaymentKit.createSign(packageParams, paternerKey_jx);
+			packageParams.put("paySign", packageSign);
+
+			String jsonStr = JsonUtils.toJson(packageParams);
+			setAttr("json", jsonStr);
+			System.out.println(jsonStr);
+//	        renderJson("{\"code\":0}");
+			renderText(jsonStr);
+		}
 
 	}