All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.beecloud.BCPayMultiApp Maven / Gradle / Ivy

/**
 * *************************
 *
 * @Date: Sep 18, 2015
 * @Time: 2:54:12 PM
 * @Author: Joseph Gao
 * 

* ************************** */ package cn.beecloud; import cn.beecloud.BCEumeration.PAY_CHANNEL; import cn.beecloud.BCEumeration.RESULT_TYPE; import cn.beecloud.bean.*; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import net.sf.json.JSONObject; /** * 主要为了一个商户下有多个收款APP使用,参考@BCPay * * @author Gao * @since 2015/9/18 */ public class BCPayMultiApp { private final static String TEST_MODE_SUPPORT_ERROR = "测试模式仅支持国内支付(WX_JSAPI暂不支持)、订单查询、订单总数查询、单笔订单查询"; private String appId; private String appSecret; private String testSecret; private String masterSecret; private Boolean sandbox = false; public BCPayMultiApp(String appId, String testSecret, String appSecret, String masterSecret) { this.appId = appId; this.testSecret = testSecret; this.appSecret = appSecret; this.masterSecret = masterSecret; } public Boolean isSandbox() { return sandbox; } public void setSandbox(Boolean sandbox) { this.sandbox = sandbox; } /** * 支付接口 * * @param order {@link BCOrder} (必填) 支付参数 * @return 调起BeeCloud支付后的返回结果 * @throws BCException */ public BCOrder startBCPay(BCOrder order) throws BCException { ValidationUtil.validateBCPay(order); Map param = new HashMap(); buildPayParam(param, order); if (sandbox) { if (order.getChannel().equals(PAY_CHANNEL.WX_JSAPI)) { throw new BCException(-2, RESULT_TYPE.OTHER_ERROR.name(), TEST_MODE_SUPPORT_ERROR); } Map ret = RequestUtil.doPost(BCUtilPrivate.getkSandboxApiPay(), param); placeSandboxOrder(order, ret); // 易宝点卡支付代码调用回调 if (order.getChannel().equals(PAY_CHANNEL.YEE_NOBANKCARD)) { RequestUtil.doGet(BCUtilPrivate.getkApiSandboxNotify() + "/" + this.appId + "/" + order.getObjectId() + "?para=", new HashMap()); } return order; } Map ret = RequestUtil.doPost(BCUtilPrivate.getkApiPay(), param); placeOrder(order, ret); return order; } /** * 退款接口 * * @param refund {@link BCRefund} (必填) 退款参数 * @return 发起退款的返回结果 * @throws BCException */ public BCRefund startBCRefund(BCRefund refund) throws BCException { checkTestModeSwitch(); ValidationUtil.validateBCRefund(refund); Map param = new HashMap(); buildRefundParam(param, refund); Map ret = RequestUtil.doPost(BCUtilPrivate.getkApiRefund(), param); refund.setObjectId(StrUtil.toStr(ret.get("id"))); if (ret.containsKey("url")) { refund.setAliRefundUrl(StrUtil.toStr(ret.get("url"))); } return refund; } /** * 订单查询(批量)接口 * * @param para {@link BCQueryParameter} (必填) 订单查询参数 * @return 订单查询返回的结果 * @throws BCException */ @SuppressWarnings("unchecked") public List startQueryBill(BCQueryParameter para) throws BCException { ValidationUtil.validateQueryBill(para); Map param = new HashMap(); buildQueryParam(param, para); if (sandbox) { Map ret = RequestUtil.doGet(BCUtilPrivate.getkApiSandboxQueryBill(), param); return generateBCOrderList((List>) ret.get("bills")); } Map ret = RequestUtil.doGet(BCUtilPrivate.getkApiQueryBill(), param); return generateBCOrderList((List>) ret.get("bills")); } /** * 订单查询(单笔,根据id)接口 * * @param objectId (必填) 订单记录唯一标识 * @return id查询返回结果 * @throws BCException */ public BCOrder startQueryBillById(String objectId) throws BCException { Map param = new HashMap(); param.put("app_id", this.appId); param.put("timestamp", System.currentTimeMillis()); if (sandbox) { param.put("app_sign", this.getAppSignatureWithTestSecret(StrUtil.toStr(param.get("timestamp")))); } else { param.put("app_sign", this.getAppSignature(StrUtil.toStr(param.get("timestamp")))); } StringBuilder urlSb = new StringBuilder(); if (sandbox) { urlSb.append(BCUtilPrivate.getkApiSandboxQueryBillById()); } else { urlSb.append(BCUtilPrivate.getkApiQueryBillById()); } urlSb.append("/"); urlSb.append(objectId); urlSb.append("?para="); Map ret = RequestUtil.doGet(urlSb.toString(), param); return generateBCOrder((Map) ret.get("pay")); } /** * 订单总数查询接口 * * @param para {@link BCQueryParameter} (必填)订单总数查询参数 * @return 订单总数查询返回的结果 * @throws BCException */ public Integer startQueryBillCount(BCQueryParameter para) throws BCException { ValidationUtil.validateQueryBill(para); Map param = new HashMap(); buildQueryCountParam(param, para); if (sandbox) { Map ret = RequestUtil.doGet(BCUtilPrivate.getkApiSandboxQueryBillCount(), param); return (Integer) ret.get("count"); } Map ret = RequestUtil.doGet(BCUtilPrivate.getkApiQueryBillCount(), param); return (Integer) ret.get("count"); } /** * 退款记录查询(批量)接口 * * @param para {@link BCQueryParameter} (必填)订单查询参数 * @return 退款查询返回的结果 * @throws BCException */ public List startQueryRefund(BCQueryParameter para) throws BCException { checkTestModeSwitch(); ValidationUtil.validateQueryRefund(para); Map param = new HashMap(); buildQueryParam(param, para); Map ret = RequestUtil.doGet(BCUtilPrivate.getkApiQueryRefund(), param); return generateBCRefundList((List>) ret.get("refunds")); } /** * 退款查询接口(根据 id) * * @param objectId (必填) 退款记录唯一标识 * @return 单笔退款记录查询返回结果 * @throws BCException */ public BCRefund startQueryRefundById(String objectId) throws BCException { checkTestModeSwitch(); Map param = new HashMap(); param.put("app_id", this.appId); param.put("timestamp", System.currentTimeMillis()); param.put("app_sign", this.getAppSignature(StrUtil.toStr(param.get("timestamp")))); StringBuilder urlSb = new StringBuilder(); urlSb.append(BCUtilPrivate.getkApiQueryRefundById()); urlSb.append("/"); urlSb.append(objectId); urlSb.append("?para="); Map ret = RequestUtil.doGet(urlSb.toString(), param); return generateBCRefund((Map) ret.get("refund")); } /** * 退款记录总数查询接口 * * @param para {@link BCQueryParameter} (必填) 退款总数查询参数 * @return 退款总数查询返回的结果 * @throws BCException */ public Integer startQueryRefundCount(BCQueryParameter para) throws BCException { checkTestModeSwitch(); ValidationUtil.validateQueryRefund(para); Map param = new HashMap(); buildQueryCountParam(param, para); Map ret = RequestUtil.doGet(BCUtilPrivate.getkApiQueryBillCount(), param); return (Integer) ret.get("count"); } /** * 退款状态更新接口 * * @param refundNo (必填)商户退款单号, 格式为:退款日期(8位) + 流水号(3~24 * 位)。不可重复,且退款日期必须是当天日期。流水号可以接受数字或英文字符,建议使用数字,但不可接受“000”。 * @param channel (必填) 渠道类型, 根据不同场景选择不同的支付方式,包含: YEE 易宝 WX 微信 KUAIQIAN 快钱 BD 百度 * @return 退款状态更新返回结果,包括(SUCCESS, PROCESSING, FAIL...) * @throws BCException */ public String startRefundUpdate(PAY_CHANNEL channel, String refundNo) throws BCException { checkTestModeSwitch(); ValidationUtil.validateQueryRefundStatus(channel, refundNo); Map param = new HashMap(); param.put("app_id", this.appId); param.put("timestamp", System.currentTimeMillis()); param.put("app_sign", this.getAppSignature(StrUtil.toStr(param.get("timestamp")))); param.put("channel", StrUtil.toStr(channel)); param.put("refund_no", refundNo); Map ret = RequestUtil.doGet(BCUtilPrivate.getkApiRefundUpdate(), param); return StrUtil.toStr(ret.get("refund_status")); } /** * 单笔打款接口 * * @param para {@link TransferParameter} (必填)单笔打款参数 * @return 如果channel类型是TRANSFER_CHANNEL.ALI_TRANSFER, 返回需要跳转支付的url, 否则返回空字符串 * @throws BCException */ public String startTransfer(TransferParameter para) throws BCException { checkTestModeSwitch(); ValidationUtil.validateBCTransfer(para); Map param = new HashMap(); buildTransferParam(param, para); Map ret = RequestUtil.doPost(BCUtilPrivate.getkApiTransfer(), param); if (ret.containsKey("url")) { return StrUtil.toStr(ret.get("url")); } return ""; } /** * 批量打款接口 * * @param para {@link TransfersParameter} (必填) 批量打款参数 * @return 批量打款跳转支付url * @throws BCException */ public String startTransfers(TransfersParameter para) throws BCException { checkTestModeSwitch(); ValidationUtil.validateBCTransfers(para); Map param = new HashMap(); buildTransfersParam(param, para); Map ret = RequestUtil.doPost(BCUtilPrivate.getkApiTransfers(), param); return StrUtil.toStr(ret.get("url")); } /** * 发起预退款审核,包括批量否决和批量同意 * * @param batchRefund (必填) 批量退款参数 * @return BCBatchRefund * @throws BCException */ public BCBatchRefund startBatchRefund(BCBatchRefund batchRefund) throws BCException { checkTestModeSwitch(); Map param = new HashMap(); param.put("channel", StrUtil.toStr(batchRefund.getChannel())); param.put("agree", batchRefund.getAgree()); param.put("ids", batchRefund.getIds()); param.put("app_id", this.appId); param.put("timestamp", System.currentTimeMillis()); param.put("app_sign", this.getAppSignature(StrUtil.toStr(param.get("timestamp")))); Map ret = RequestUtil.doPut(BCUtilPrivate.getApiBatchRefund(), param); if (ret.containsKey("result_map")) { batchRefund.setIdResult((Map) ret.get("result_map")); if (ret.containsKey("url")) { batchRefund.setAliRefundUrl(StrUtil.toStr(ret.get("url"))); } } return batchRefund; } /** * 境外支付(paypal)接口 * * @param order {@link BCInternationlOrder} (必填) * @return 支付后返回的order * @throws BCException */ public BCInternationlOrder startBCInternatioalPay(BCInternationlOrder order) throws BCException { checkTestModeSwitch(); ValidationUtil.validateBCInternatioalPay(order); Map param = new HashMap(); buildInternatioalPayParam(param, order); Map ret = RequestUtil.doPost(BCUtilPrivate.getApiInternationalPay(), param); placePayPalOrder(order, ret); return order; } /** * 代付接口 * * @param bcTransferParameter * {@link BCTransferParameter} (必填) 支付参数 * @return 调起BeeCloud代付后的返回结果 * @throws BCException */ public void startBCTransfer(BCTransferParameter bcTransferParameter) throws BCException { ValidationUtil.validateBCTransfer(bcTransferParameter); Map param = new HashMap(); buildBCTransferParam(param, bcTransferParameter); RequestUtil.doPost(BCUtilPrivate.getkApiBCTransfer(), param); } public List fetchBCTransfersBanks(BCEumeration.BC_TRANSFER_BANK_TYPE type) throws BCException{ Map param = new HashMap(); param.put("type", StrUtil.toStr(type)); param.put("app_id", this.appId); Map ret = RequestUtil.doGet(BCUtilPrivate.getkApiBCTransferBanks(), param); return (List) ret.get("bank_list"); } /** * @param sign Webhook提供的签名 * @param timestamp Webhook提供的timestamp,注意是String格式 * @return 签名是否正确 */ public static boolean verifySign(String sign, String timestamp) { String mySign = MD5.sign(BCCache.getAppID() + BCCache.getAppSecret(), timestamp, "UTF-8"); if (sign.equals(mySign)) return true; else return false; } /** * 构建支付rest api参数 */ private void buildPayParam(Map param, BCOrder para) { param.put("app_id", this.appId); param.put("timestamp", System.currentTimeMillis()); if (sandbox) { param.put("app_sign", this.getAppSignatureWithTestSecret(StrUtil.toStr(param.get("timestamp")))); } else { param.put("app_sign", this.getAppSignature(StrUtil.toStr(param.get("timestamp")))); } param.put("channel", StrUtil.toStr(para.getChannel())); param.put("total_fee", para.getTotalFee()); param.put("bill_no", para.getBillNo()); param.put("title", para.getTitle()); if (para.getReturnUrl() != null) { param.put("return_url", para.getReturnUrl()); } if (para.getOptional() != null && para.getOptional().size() > 0) { param.put("optional", para.getOptional()); } if (para.getOpenId() != null) { param.put("openid", para.getOpenId()); } if (para.getIdentityId() != null) { param.put("identity_id", para.getIdentityId()); } if (para.getShowUrl() != null) { param.put("show_url", para.getShowUrl()); } if (para.getQrPayMode() != null) { if (para.getQrPayMode().ordinal() == 2) { param.put("qr_pay_mode", String.valueOf(para.getQrPayMode().ordinal() + 1)); } else { param.put("qr_pay_mode", String.valueOf(para.getQrPayMode().ordinal())); } } if (para.getBillTimeout() != null) { param.put("bill_timeout", para.getBillTimeout()); } if (para.getChannel().equals(PAY_CHANNEL.YEE_NOBANKCARD)) { param.put("cardno", para.getCardNo()); param.put("cardpwd", para.getCardPwd()); param.put("frqid", para.getFrqid()); } if (para.getGatewayBank() != null) { param.put("bank", StrUtil.toStr(para.getGatewayBank())); } if (para.getBcExpressCardNo() != null) { param.put("card_no", StrUtil.toStr(para.getBcExpressCardNo())); } if (para.isUseApp() != null) { param.put("use_app", para.isUseApp()); } if (para.getNotifyUrl() != null) { param.put("notify_url", para.getNotifyUrl()); } } private Object getAppSignatureWithTestSecret(String timestamp) { String str = appId + timestamp + testSecret; return BCUtilPrivate.getMessageDigest(str); } /** * 构建退款rest api参数 */ private void buildRefundParam(Map param, BCRefund para) { param.put("app_id", this.appId); param.put("timestamp", System.currentTimeMillis()); param.put("app_sign", this.getAppSignatureWithMasterSecret(StrUtil.toStr(param.get("timestamp")))); param.put("refund_no", para.getRefundNo()); param.put("bill_no", para.getBillNo()); param.put("refund_fee", para.getRefundFee()); if (para.getChannel() != null) { param.put("channel", StrUtil.toStr(para.getChannel())); } if (para.isNeedApproval() != null) { param.put("need_approval", para.isNeedApproval()); } if (para.getOptional() != null && para.getOptional().size() > 0) param.put("optional", para.getOptional()); } /** * 构建查询rest api参数 */ private void buildQueryParam(Map param, BCQueryParameter para) { param.put("app_id", this.appId); param.put("timestamp", System.currentTimeMillis()); if (sandbox) { param.put("app_sign", this.getAppSignatureWithTestSecret(StrUtil.toStr(param.get("timestamp")))); } else { param.put("app_sign", this.getAppSignature(StrUtil.toStr(param.get("timestamp")))); } if (para.getChannel() != null) { param.put("channel", StrUtil.toStr(para.getChannel())); } if (para.getBillNo() != null) { param.put("bill_no", para.getBillNo()); } if (para.getRefundNo() != null) { param.put("refund_no", para.getRefundNo()); } if (para.getSkip() != null) { param.put("skip", para.getSkip()); } if (para.getLimit() != null) { param.put("limit", para.getLimit()); } if (para.getStartTime() != null) { param.put("start_time", para.getStartTime().getTime()); } if (para.getEndTime() != null) { param.put("end_time", para.getEndTime().getTime()); } if (para.getPayResult() != null) { param.put("spay_result", para.getPayResult()); } if (para.getRefundResult() != null) { param.put("refund_result", para.getRefundResult()); } if (para.getNeedDetail() != null && para.getNeedDetail()) { param.put("need_detail", para.getNeedDetail()); } if (para.getNeedApproval() != null && para.getNeedApproval()) { param.put("need_approval", para.getNeedApproval()); } } /** * 构建订单总数查询rest api参数 */ private void buildQueryCountParam(Map param, BCQueryParameter para) { param.put("app_id", this.appId); param.put("timestamp", System.currentTimeMillis()); if (sandbox) { param.put("app_sign", this.getAppSignatureWithTestSecret(StrUtil.toStr(param.get("timestamp")))); } else { param.put("app_sign", this.getAppSignature(StrUtil.toStr(param.get("timestamp")))); } if (para.getChannel() != null) { param.put("channel", StrUtil.toStr(para.getChannel())); } if (para.getBillNo() != null) { param.put("bill_no", para.getBillNo()); } if (para.getRefundNo() != null) { param.put("refund_no", para.getRefundNo()); } if (para.getStartTime() != null) { param.put("start_time", para.getStartTime().getTime()); } if (para.getEndTime() != null) { param.put("end_time", para.getEndTime().getTime()); } if (para.getPayResult() != null) { param.put("spay_result", para.getPayResult()); } if (para.getRefundResult() != null) { param.put("refund_result", para.getRefundResult()); } if (para.getNeedApproval() != null && para.getNeedApproval()) { param.put("need_approval", para.getNeedApproval()); } } /** * 构建境外支付rest api参数 */ private void buildInternatioalPayParam(Map param, BCInternationlOrder order) { param.put("app_id", this.appId); param.put("timestamp", System.currentTimeMillis()); param.put("app_sign", this.getAppSignature(StrUtil.toStr(param.get("timestamp")))); param.put("channel", StrUtil.toStr(order.getChannel())); param.put("currency", StrUtil.toStr(order.getCurrency())); param.put("bill_no", order.getBillNo()); param.put("title", order.getTitle()); param.put("total_fee", order.getTotalFee()); if (order.getCreditCardInfo() != null) { Map map = new HashMap(); param.put("credit_card_info", map); map.put("card_number", order.getCreditCardInfo().getCardNo()); map.put("expire_month", order.getCreditCardInfo().getExpireMonth()); map.put("expire_year", order.getCreditCardInfo().getExpireYear()); map.put("cvv", order.getCreditCardInfo().getCvv()); map.put("first_name", order.getCreditCardInfo().getFirstName()); map.put("last_name", order.getCreditCardInfo().getLastName()); map.put("card_type", StrUtil.toStr(order.getCreditCardInfo().getCardType())); } if (order.getCreditCardId() != null) { param.put("credit_card_id", order.getCreditCardId()); } if (order.getReturnUrl() != null) { param.put("return_url", order.getReturnUrl()); } } /** * 构建单笔打款rest api参数 */ private void buildTransferParam(Map param, TransferParameter para) { param.put("app_id", this.appId); param.put("timestamp", System.currentTimeMillis()); param.put("app_sign", this.getAppSignatureWithMasterSecret(StrUtil.toStr(param.get("timestamp")))); param.put("channel", StrUtil.toStr(para.getChannel())); param.put("transfer_no", para.getTransferNo()); param.put("total_fee", para.getTotalFee()); param.put("desc", para.getDescription()); param.put("channel_user_id", para.getChannelUserId()); if (para.getChannelUserName() != null) { param.put("channel_user_name", para.getChannelUserName()); } if (para.getRedpackInfo() != null) { Map redpackInfo = new HashMap(); redpackInfo.put("send_name", para.getRedpackInfo().getSendName()); redpackInfo.put("wishing", para.getRedpackInfo().getWishing()); redpackInfo.put("act_name", para.getRedpackInfo().getActivityName()); param.put("redpack_info", redpackInfo); } if (para.getAccountName() != null) { param.put("account_name", para.getAccountName()); } } /** * 构建批量打款rest api参数 */ private void buildTransfersParam(Map param, TransfersParameter para) { param.put("app_id", this.appId); param.put("timestamp", System.currentTimeMillis()); param.put("app_sign", this.getAppSignatureWithMasterSecret(StrUtil.toStr(param.get("timestamp")))); param.put("channel", "ALI"); param.put("batch_no", para.getBatchNo()); param.put("account_name", para.getAccountName()); List> transferList = new ArrayList>(); for (ALITransferData data : para.getTransferDataList()) { Map map = new HashMap(); map.put("transfer_id", data.getTransferId()); map.put("receiver_account", data.getReceiverAccount()); map.put("receiver_name", data.getReceiverName()); map.put("transfer_fee", data.getTransferFee()); map.put("transfer_note", data.getTransferNote()); transferList.add(map); } param.put("transfer_data", transferList); } /** * 生成返回BCOrder list */ private static List generateBCOrderList(List> bills) { List bcOrderList = new ArrayList(); for (Map bill : bills) { BCOrder bcOrder = new BCOrder(); generateBCOrderBean(bill, bcOrder); bcOrderList.add(bcOrder); } return bcOrderList; } /** * 生成返回BCOrder */ private static BCOrder generateBCOrder(Map bill) { BCOrder bcOrder = new BCOrder(); generateBCOrderBean(bill, bcOrder); return bcOrder; } /** * 生成返回BCRefund list */ private static List generateBCRefundList(List> refundList) { List bcRefundList = new ArrayList(); for (Map refund : refundList) { BCRefund bcRefund = new BCRefund(); generateBCRefundBean(refund, bcRefund); bcRefundList.add(bcRefund); } return bcRefundList; } /** * 生成返回BCRefund */ private static BCRefund generateBCRefund(Map refund) { BCRefund bcRefund = new BCRefund(); generateBCRefundBean(refund, bcRefund); return bcRefund; } /** * 构建返回BCOrder bean */ private static void generateBCOrderBean(Map bill, BCOrder bcOrder) { bcOrder.setObjectId(StrUtil.toStr(bill.get("id"))); bcOrder.setBillNo(StrUtil.toStr(bill.get("bill_no"))); bcOrder.setTotalFee((Integer) bill.get("total_fee")); bcOrder.setTitle(StrUtil.toStr(bill.get("title"))); bcOrder.setChannel(PAY_CHANNEL.valueOf(StrUtil.toStr(bill.get("sub_channel")))); bcOrder.setResult(((Boolean) bill.get("spay_result"))); if (bill.containsKey("trade_no") && bill.get("trade_no") != null) { bcOrder.setChannelTradeNo(StrUtil.toStr(bill.get("trade_no"))); } bcOrder.setOptionalString((StrUtil.toStr(bill.get("optional")))); bcOrder.setDateTime( BCUtilPrivate.transferDateFromLongToString((Long) bill.get("create_time"))); if (bill.containsKey("message_detail")) { bcOrder.setMessageDetail(StrUtil.toStr(bill.get("message_detail"))); } bcOrder.setRefundResult((Boolean) bill.get("refund_result")); bcOrder.setRevertResult((Boolean) bill.get("revert_result")); } /** * 构建返回BCRefund bean */ private static void generateBCRefundBean(Map refund, BCRefund bcRefund) { bcRefund.setObjectId(StrUtil.toStr(refund.get("id"))); bcRefund.setBillNo(StrUtil.toStr(refund.get("bill_no"))); bcRefund.setChannel(PAY_CHANNEL.valueOf(StrUtil.toStr(refund.get("sub_channel")))); bcRefund.setFinished((Boolean) refund.get("finish")); bcRefund.setDateTime( BCUtilPrivate.transferDateFromLongToString((Long) refund.get("create_time"))); bcRefund.setOptionalString(StrUtil.toStr(refund.get("optional"))); bcRefund.setRefunded((Boolean) refund.get("result")); bcRefund.setTitle(StrUtil.toStr(refund.get("title"))); bcRefund.setTotalFee((Integer) refund.get("total_fee")); bcRefund.setRefundFee((Integer) refund.get("refund_fee")); bcRefund.setRefundNo(StrUtil.toStr(refund.get("refund_no"))); bcRefund.setDateTime( BCUtilPrivate.transferDateFromLongToString((Long) refund.get("create_time"))); if (refund.containsKey("message_detail")) { bcRefund.setMessageDetail(StrUtil.toStr(refund.get("message_detail"))); } } /** * 构建WXJSAPI返回Map */ private static Map generateWXJSAPIMap(Map ret) { HashMap map = new HashMap(); map.put("appId", ret.get("app_id")); map.put("package", ret.get("package")); map.put("nonceStr", ret.get("nonce_str")); map.put("timeStamp", ret.get("timestamp")); map.put("paySign", ret.get("pay_sign")); map.put("signType", ret.get("sign_type")); return map; } /** * 组建返回订单 */ private static void placeOrder(BCOrder order, Map ret) { order.setObjectId(StrUtil.toStr(ret.get("id"))); switch (order.getChannel()) { case WX_NATIVE: case BC_NATIVE: if (ret.containsKey("code_url") && null != ret.get("code_url")) { order.setCodeUrl(StrUtil.toStr(ret.get("code_url"))); } break; case WX_JSAPI: order.setWxJSAPIMap(generateWXJSAPIMap(ret)); break; case ALI_WEB: case ALI_QRCODE: case ALI_WAP: if (ret.containsKey("html") && null != ret.get("html") && ret.containsKey("url") && null != ret.get("url")) { order.setHtml(StrUtil.toStr(ret.get("html"))); order.setUrl(StrUtil.toStr(ret.get("url"))); } break; case UN_WEB: case UN_WAP: case JD_WAP: case JD_WEB: case KUAIQIAN_WAP: case KUAIQIAN_WEB: case BC_GATEWAY: case CP_WEB: if (ret.containsKey("html") && null != ret.get("html")) { order.setHtml(StrUtil.toStr(ret.get("html"))); } break; case YEE_WAP: case YEE_WEB: case BD_WEB: case BD_WAP: case BC_EXPRESS: if (ret.containsKey("url") && null != ret.get("url")) { order.setUrl(StrUtil.toStr(ret.get("url"))); } default: break; } } /** * 组建返回境外支付订单 */ private static void placePayPalOrder(BCInternationlOrder order, Map ret) { order.setObjectId(StrUtil.toStr(ret.get("id"))); switch (order.getChannel()) { case PAYPAL_PAYPAL: order.setUrl(StrUtil.toStr(ret.get("url"))); break; case PAYPAL_CREDITCARD: order.setCreditCardId(StrUtil.toStr(ret.get("credit_card_id"))); break; default: break; } } /** * 组建返回沙箱支付订单 */ private static void placeSandboxOrder(BCOrder order, Map ret) { order.setObjectId(StrUtil.toStr(ret.get("id"))); switch (order.getChannel()) { case WX_NATIVE: if (ret.containsKey("url") && null != ret.get("url")) { order.setCodeUrl(StrUtil.toStr(ret.get("url"))); } break; case WX_JSAPI: order.setWxJSAPIMap(generateWXJSAPIMap(ret)); break; case ALI_WEB: case ALI_QRCODE: case ALI_WAP: if (ret.containsKey("url") && null != ret.get("url")) { order.setHtml(BCUtil.generateSandboxHtmlWithUrl(StrUtil.toStr(ret.get("url")))); order.setUrl(StrUtil.toStr(ret.get("url"))); } break; case UN_WEB: case JD_WAP: case JD_WEB: case KUAIQIAN_WAP: case KUAIQIAN_WEB: if (ret.containsKey("url") && null != ret.get("url")) { order.setHtml(BCUtil.generateSandboxHtmlWithUrl(StrUtil.toStr(ret.get("url")))); } break; case YEE_WAP: case YEE_WEB: case BD_WEB: case BD_WAP: if (ret.containsKey("url") && null != ret.get("url")) { order.setUrl(StrUtil.toStr(ret.get("url"))); } default: break; } } /** * 检查某一借口是否支持测试模式 */ private void checkTestModeSwitch() throws BCException { if (sandbox) { throw new BCException(-2, RESULT_TYPE.OTHER_ERROR.name(), TEST_MODE_SUPPORT_ERROR); } } private String getAppSignature(String timeStamp) { String str = appId + timeStamp + appSecret; return BCUtilPrivate.getMessageDigest(str); } private String getAppSignatureWithMasterSecret(String timeStamp) { String str = appId + timeStamp + masterSecret; return BCUtilPrivate.getMessageDigest(str); } /** * 构建BC代付rest api参数 */ private void buildBCTransferParam(Map param, BCTransferParameter para) { param.put("app_id", appId); param.put("timestamp", System.currentTimeMillis()); if (sandbox) { param.put("app_sign", this.getAppSignatureWithTestSecret(StrUtil.toStr(param .get("timestamp")))); } else { param.put("app_sign", this.getAppSignature(StrUtil.toStr(param.get("timestamp")))); } param.put("total_fee", para.getTotalFee()); param.put("bill_no", para.getBillNo()); param.put("title", para.getTitle()); param.put("trade_source", para.getTradeSource()); param.put("bank_fullname", para.getBankFullName()); param.put("card_type", para.getCardType()); param.put("account_type", para.getAccountType()); param.put("account_no", para.getAccountNo()); param.put("account_name", para.getAccountName()); if (!StrUtil.empty(para.getMobile())) param.put("mobile", para.getBankFullName()); if (!StrUtil.empty(para.getOptional())) param.put("optional", para.getOptional()); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy