e80df919
atao
init
|
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
|
/**
* 公众号支付js-sdk
*/
public void index_default() {
// openId,采用 网页授权获取 access_token API:SnsAccessTokenApi获取
String openId = "";
// 统一下单文档地址: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);
params.put("body", "JFinal2.0极速开发");
params.put("out_trade_no", "977773682111");
params.put("total_fee", "1");
String ip = IpKit.getRealIp(getRequest());
if (StrKit.isBlank(ip)) {
ip = "127.0.0.1";
}
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);
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(return_msg);
return;
}
String result_code = result.get("result_code");
if (StrKit.isBlank(result_code) || !"SUCCESS".equals(result_code)) {
renderText(return_msg);
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);
packageParams.put("paySign", packageSign);
String jsonStr = JsonUtils.toJson(packageParams);
setAttr("json", jsonStr);
System.out.println(jsonStr);
render("/jsp/pay.jsp");
}
/**
* 支付成功通知
*/
@Clear
public void pay_notify() {
// 支付结果通用通知文档: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7
String xmlMsg = HttpKit.readData(getRequest());
logger.info("接收到异步支付通知:xmlMsg=" + xmlMsg);
Map<String, String> params = PaymentKit.xmlToMap(xmlMsg);
String result_code = params.get("result_code");
// 总金额
String totalFee = params.get("total_fee");
// 商户订单号 支付单号
String payOrderId = params.get("out_trade_no");
// 微信支付订单号
String transId = params.get("transaction_id");
// 支付完成时间,格式为yyyyMMddHHmmss
String timeEnd = params.get("time_end");
//支付流水保存
PayOrderFlow payOrderFlow = new PayOrderFlow();
payOrderFlow.setPayOrderFlowId(SequenceUtil.getNextOrderId(SequenceTypeEnum.ORDER_PAY_FLOW_WXGZH.value()));
payOrderFlow.setPayOrderId(payOrderId);
payOrderFlow.setTradeNo(transId);
//传回的金额以 分 为单位,转换为double,然后转换为 BigDecimal类型
payOrderFlow.setBuyerPayAmount(new BigDecimal(new Double(totalFee) / 100));
//付款时间
payOrderFlow.setGmtPayment(new Date());
//处理环节
payOrderFlow.setProcLink(2);
//处理时间
payOrderFlow.setProcTime(new Date());
//支付类型
payOrderFlow.setPayType(Integer.valueOf(PayOrderEnum.PAY_TYPE_WXGZH.getValue()));
//支付流水类型
payOrderFlow.setPayFlowType(Integer.valueOf(PayOrderEnum.PAY_FLOW_TYPE_ASYN.getValue()));
//创建人
payOrderFlow.setCreateEmpid("-1");
//创建时间
payOrderFlow.setCreateDate(new Date());
//修改人
payOrderFlow.setModfiyEmpid("-1");
//修改时间
payOrderFlow.setModfiyDate(new Date());
boolean flag = false;
// 注意重复通知的情况,同一订单号可能收到多次通知,请注意一定先判断订单状态
// 避免已经成功、关闭、退款的订单被再次更新
Map<String, String> xml = new HashMap<String, String>();
if (PaymentKit.verifyNotify(params, paternerKey)) {
if (("SUCCESS").equals(result_code)) {
//用户标识
String openId = params.get("openid");
payOrderFlow.setBuyerLogonId(openId);
//更新订单信息
OrderService orderService = Duang.duang(OrderService.class, new Tx());
logger.info("微信支付异步通知订单更新 payOrder=" + payOrderId);
flag = orderService.payOrderSuccess(payOrderId, transId);
logger.info("微信支付异步通知订单更新结果为 flag=" + flag);
xml.put("return_code", "SUCCESS");
xml.put("return_msg", "OK");
} else {
String err_code = params.get("err_code");
String err_code_des = params.get("err_code_des");
logger.info("微信支付异步通知业务异常:err_code=" + err_code + "; err_code_des=" + err_code_des);
xml.put("return_code", "FAIL");
xml.put("return_msg", "业务失败");
}
} else {
logger.info("微信支付异步通知验证签名失败,返回FAIL");
xml.put("return_code", "FAIL");
xml.put("return_msg", "签名失败!");
flag = false;
}
if (flag) {
payOrderFlow.setProcResult(1);
} else {
payOrderFlow.setProcResult(2);
}
payOrderFlow.save();
renderText(PaymentKit.toXml(xml));
return;
}
/**
* @author Javen
* 2016年5月14日
* PC扫码支付获取二维码(模式一)
*/
public String getCodeUrl(String productId) {
String url = "weixin://wxpay/bizpayurl?sign=%s&appid=%s&mch_id=%s&product_id=%s&time_stamp=%s&nonce_str=%s";
String timeStamp = Long.toString(System.currentTimeMillis() / 1000);
String nonceStr = Long.toString(System.currentTimeMillis());
Map<String, String> packageParams = new HashMap<String, String>();
packageParams.put("appid", appid);
packageParams.put("mch_id", partner);
packageParams.put("product_id", productId);
packageParams.put("time_stamp", timeStamp);
packageParams.put("nonce_str", nonceStr);
String packageSign = PaymentKit.createSign(packageParams, paternerKey);
return String.format(url, packageSign, appid, partner, productId, timeStamp, nonceStr);
}
public void test() {
String product_id = "001";
renderText(getCodeUrl(product_id));
}
/**
* @author Javen
* 2016年5月14日
* PC扫码支付回调(模式一)
*/
public void wxpay() {
String result = HttpKit.readData(getRequest());
System.out.println("回调结果=" + result);
/**
* 获取返回的信息内容中各个参数的值
*/
Map<String, String> map = PaymentKit.xmlToMap(result);
for (String key : map.keySet()) {
System.out.println("key= " + key + " and value= " + map.get(key));
}
String appid = map.get("appid");
String openid = map.get("openid");
String mch_id = map.get("mch_id");
String is_subscribe = map.get("is_subscribe");
String nonce_str = map.get("nonce_str");
String product_id = map.get("product_id");
String sign = map.get("sign");
Map<String, String> packageParams = new HashMap<String, String>();
packageParams.put("appid", appid);
packageParams.put("openid", openid);
packageParams.put("mch_id", mch_id);
packageParams.put("is_subscribe", is_subscribe);
packageParams.put("nonce_str", nonce_str);
packageParams.put("product_id", product_id);
String packageSign = PaymentKit.createSign(packageParams, paternerKey);
if (sign.equals(packageSign)) {
// 统一下单文档地址: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", mch_id);
params.put("body", "测试扫码支付");
String out_trade_no = Long.toString(System.currentTimeMillis());
params.put("out_trade_no", out_trade_no);
int price = ((int)(Float.valueOf(10) * 100));
params.put("total_fee", price + "");
params.put("attach", out_trade_no);
String ip = IpKit.getRealIp(getRequest());
if (StrKit.isBlank(ip)) {
ip = "127.0.0.1";
}
params.put("spbill_create_ip", ip);
params.put("trade_type", TradeType.NATIVE.name());
params.put("nonce_str", System.currentTimeMillis() / 1000 + "");
params.put("notify_url", notify_url);
params.put("openid", openid);
String paysign = PaymentKit.createSign(params, paternerKey);
params.put("sign", paysign);
String xmlResult = PaymentApi.pushOrder(params);
System.out.println("prepay_xml>>>" + xmlResult);
Map<String, String> payResult = PaymentKit.xmlToMap(xmlResult);
String return_code = payResult.get("return_code");
String return_msg = payResult.get("return_msg");
if (StrKit.isBlank(return_code) || !"SUCCESS".equals(return_code)) {
System.out.println("return_code>>>" + return_msg);
return;
}
if (StrKit.isBlank(return_msg) || !"OK".equals(return_msg)) {
System.out.println("return_msg>>>>" + return_msg);
return;
}
// 以下字段在return_code 和result_code都为SUCCESS的时候有返回
String prepay_id = payResult.get("prepay_id");
Map<String, String> prepayParams = new HashMap<String, String>();
prepayParams.put("return_code", "SUCCESS");
prepayParams.put("appId", appid);
prepayParams.put("mch_id", mch_id);
prepayParams.put("nonceStr", System.currentTimeMillis() + "");
prepayParams.put("prepay_id", prepay_id);
prepayParams.put("result_code", "SUCCESS");
String prepaySign = PaymentKit.createSign(prepayParams, paternerKey);
prepayParams.put("sign", prepaySign);
String xml = PaymentKit.toXml(prepayParams);
System.out.println(xml);
renderText(xml);
}
}
/**
* 刷卡支付
* 文档:https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=5_1
*/
public void micropay() {
String url = "https://api.mch.weixin.qq.com/pay/micropay";
String total_fee = "1";
String auth_code = getPara("auth_code");//测试时直接手动输入刷卡页面上的18位数字
Map<String, String> params = new HashMap<String, String>();
params.put("appid", appid);
params.put("mch_id", partner);
params.put("device_info", "javen205");//终端设备号
params.put("nonce_str", System.currentTimeMillis() / 1000 + "");
params.put("body", "刷卡支付测试");
// params.put("detail", "json字符串");//非必须
params.put("attach", "javen205");//附加参数非必须
String out_trade_no = System.currentTimeMillis() + "";
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";
}
params.put("spbill_create_ip", ip);
params.put("auth_code", auth_code);
String sign = PaymentKit.createSign(params, paternerKey);
params.put("sign", sign);
String xmlResult = HttpUtils.post(url, PaymentKit.toXml(params));
//同步返回结果
System.out.println("xmlResult:" + xmlResult);
Map<String, String> result = PaymentKit.xmlToMap(xmlResult);
String return_code = result.get("return_code");
if (StrKit.isBlank(return_code) || !"SUCCESS".equals(return_code)) {
//通讯失败
String err_code = result.get("err_code");
//用户支付中,需要输入密码
if (err_code.equals("USERPAYING")) {
//等待5秒后调用【查询订单API】https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_2
}
renderText("通讯失败>>" + xmlResult);
return;
}
String result_code = result.get("result_code");
if (StrKit.isBlank(result_code) || !"SUCCESS".equals(result_code)) {
//支付失败
renderText("支付失败>>" + xmlResult);
return;
}
//支付成功 返回参会入库 业务逻辑处理
renderText(xmlResult);
}
/**
* PC支付模式二,PC支付不需要openid
*/
public void pcModeTwo() {
// 统一下单文档地址: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);
params.put("body", "JFinal2.2极速开发");
// 商品ID trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。
params.put("product_id", "1");
// 商户订单号 商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号
params.put("out_trade_no", "97777368222");
params.put("total_fee", "1");
String ip = IpKit.getRealIp(getRequest());
if (StrKit.isBlank(ip)) {
ip = "127.0.0.1";
}
params.put("spbill_create_ip", ip);
params.put("trade_type", TradeType.NATIVE.name());
params.put("nonce_str", System.currentTimeMillis() / 1000 + "");
params.put("notify_url", notify_url);
String sign = PaymentKit.createSign(params, paternerKey);
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(return_msg);
return;
}
String result_code = result.get("result_code");
if (StrKit.isBlank(result_code) || !"SUCCESS".equals(result_code)) {
renderText(return_msg);
return;
}
// 以下字段在return_code 和result_code都为SUCCESS的时候有返回
String prepay_id = result.get("prepay_id");
// trade_type为NATIVE是有返回,可将该参数值生成二维码展示出来进行扫码支付
String code_url = result.get("code_url");
setAttr("code_url", code_url);
render("/jsp/pc_pay.jsp");
}
/**
* wap支付第一版本
*/
public void wap1() {
Map<String, String> params = new HashMap<String, String>();
params.put("appid", appid);
params.put("mch_id", partner);
params.put("body", "JFinal2.0极速开发");
params.put("out_trade_no", "977773682111");
params.put("total_fee", "1");
String ip = IpKit.getRealIp(getRequest());
if (StrKit.isBlank(ip)) {
ip = "127.0.0.1";
}
params.put("spbill_create_ip", ip);
params.put("trade_type", TradeType.WAP.name());
params.put("nonce_str", System.currentTimeMillis() / 1000 + "");
params.put("notify_url", notify_url);
String sign = PaymentKit.createSign(params, paternerKey);
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(return_msg);
return;
}
String result_code = result.get("result_code");
if (StrKit.isBlank(result_code) || !"SUCCESS".equals(result_code)) {
renderText(return_msg);
return;
}
// 以下字段在return_code 和result_code都为SUCCESS的时候有返回
String prepayId = result.get("prepay_id");
String url = PaymentApi.getDeepLink(appid, prepayId, paternerKey);
// 微信那边的开发建议用a标签打开该链接
setAttr("url", url);
}
/**
* wap支付第二版
*/
public void wap2() {
Map<String, String> params = new HashMap<String, String>();
params.put("appid", appid);
params.put("mch_id", partner);
params.put("body", "JFinal2.0极速开发");
params.put("out_trade_no", "977773682111");
params.put("total_fee", "1");
String ip = IpKit.getRealIp(getRequest());
if (StrKit.isBlank(ip)) {
ip = "127.0.0.1";
}
params.put("spbill_create_ip", ip);
params.put("trade_type", TradeType.MWEB.name());
params.put("nonce_str", System.currentTimeMillis() / 1000 + "");
params.put("notify_url", notify_url);
String sign = PaymentKit.createSign(params, paternerKey);
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(return_msg);
return;
}
String result_code = result.get("result_code");
if (StrKit.isBlank(result_code) || !"SUCCESS".equals(result_code)) {
renderText(return_msg);
return;
}
// 以下字段在return_code 和result_code都为SUCCESS的时候有返回
String url = result.get("mweb_url");
// 微信那边的开发建议用a标签打开该链接
setAttr("url", url);
}
/*************************************输入车牌查询支付单支付功能*******************************************************/
/**
* 支付页面-入口.<br/>
*/
|