com.egzosn.pay.common.util.Util类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(494)

本文整理了Java中com.egzosn.pay.common.util.Util类的一些代码示例,展示了Util类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util类的具体详情如下:
包路径:com.egzosn.pay.common.util.Util
类名称:Util

Util介绍

暂无

代码示例

代码示例来源:origin: egzosn/pay-java-parent

private static int bigEndianByteToInt(byte[] bytes) {
  return Util.byteToInt(back(bytes));
}

代码示例来源:origin: egzosn/pay-java-parent

/**
 * Convert hex string to byte[]
 *
 * @param hexString the hex string
 * @return byte[]
 */
public static byte[] hexStringToBytes(String hexString) {
  if (hexString == null || "".equals(hexString)) {
    return null;
  }
  hexString = hexString.toUpperCase();
  int length = hexString.length() / 2;
  char[] hexChars = hexString.toCharArray();
  byte[] d = new byte[length];
  for (int i = 0; i < length; i++) {
    int pos = i * 2;
    d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
  }
  return d;
}

代码示例来源:origin: egzosn/pay-java-parent

/**
 * 将字节数组转换为十六进制字符数组
 *
 * @param data        byte[]
 * @param toLowerCase <code>true</code> 传换成小写格式 , <code>false</code> 传换成大写格式
 * @return 十六进制char[]
 */
public static char[] encodeHex(byte[] data, boolean toLowerCase) {
  return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER);
}

代码示例来源:origin: egzosn/pay-java-parent

/**
 * 返回创建的订单信息
 *
 * @param order 支付订单
 *
 * @return 订单信息
 * @see PayOrder 支付订单信息
 */
@Override
public Map<String, Object> orderInfo(PayOrder order) {
  Map<String, Object> params = new HashMap<>(7);
  params.put("payee_id", order.getAuthCode());
  params.put("amount", Util.conversionAmount(order.getPrice()));
  params.put("client_reference_id", order.getOutTradeNo());
  if (null == order.getCurType()) {
    order.setCurType(CurType.USD);
  }
  params.put("currency", order.getCurType());
  params.put("description", order.getSubject());
  return params;
}

代码示例来源:origin: egzosn/pay-java-parent

parameters.put("order_amt", Util.conversionCentAmount(order.getPrice()));

代码示例来源:origin: egzosn/pay-java-parent

/**
 * 将字节数组转换为十六进制字符串
 *
 * @param data byte[]
 * @return 十六进制String
 */
public static String encodeHexString(byte[] data) {
  return encodeHexString(data, true);
}

代码示例来源:origin: egzosn/pay-java-parent

/**
 * 根据字节数组获得值(十六进制数字)
 *
 * @param bytes 字节数组
 * @return 16进制字符串
 */
public static String getHexString(byte[] bytes) {
  return getHexString(bytes, true);
}

代码示例来源:origin: egzosn/pay-java-parent

/**
 * 获取支付平台所需的订单信息
 *
 * @param order 支付订单
 * @return 订单信息
 * @see PayOrder 支付订单信息
 */
@Override
public JSONObject orderInfo(PayOrder order) {
  TreeMap<String, String> data = new TreeMap<>();
  data.put("access_token",  getAccessToken());
  data.put("paymoney", Util.conversionAmount(order.getPrice()).toString());
  String apbNonce = SignUtils.randomStr();
  String sign = createSign(SignUtils.parameterText(data, "") + apbNonce, payConfigStorage.getInputCharset());
  data.put("PayMoney", data.remove("paymoney"));
  String params =  SignUtils.parameterText(data) +  "&apb_nonce=" + apbNonce + "&sign=" + sign;
  try {
    JSONObject json = execute(getUrl(order.getTransactionType())+ "?" +  params, MethodType.GET, null);
    //友店比较特殊,需要在下完预订单后,自己存储 order_sn 对应 微信官方文档 out_trade_no
    order.setOutTradeNo(json.getString("order_sn"));
    return json;
  } catch (PayErrorException e) {
    throw  e;
  }
}

代码示例来源:origin: egzosn/pay-java-parent

/**
 * 申请退款接口
 *
 * @param refundOrder   退款订单信息
 * @return 退款返回结果集
 */
@Override
public Map<String, Object> refund(RefundOrder refundOrder) {
  Map<String, Object> params = new HashMap<>();
  //商户代码
  params.put("mchnt_cd", payConfigStorage.getPid());
  //原交易日期
  params.put("origin_order_date", refundOrder.getOrderDate());
  //原订单号
  params.put("origin_order_id", refundOrder.getTradeNo());
  //退款金额
  params.put("refund_amt", Util.conversionCentAmount(refundOrder.getRefundAmount()));
  //备注
  params.put("rem", "");
  params.put("md5", createSign(SignUtils.parameters2MD5Str(params, "|"), payConfigStorage.getInputCharset()));
  JSONObject resultJson = getHttpRequestTemplate().postForObject(getReqUrl() + URL_FuiouSmpRefundGate, params, JSONObject.class);
  return resultJson;
}

代码示例来源:origin: egzosn/pay-java-parent

/**
 * 将字节数组转换为十六进制字符串
 *
 * @param data        byte[]
 * @param toLowerCase <code>true</code> 传换成小写格式 , <code>false</code> 传换成大写格式
 * @return 十六进制String
 */
public static String encodeHexString(byte[] data, boolean toLowerCase) {
  return encodeHexString(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER);
}

代码示例来源:origin: egzosn/pay-java-parent

orderInfo.put("total_fee", Util.conversionAmount(order.getPrice()).toString() );

代码示例来源:origin: egzosn/pay-java-parent

case WEB:
case B2B:
  params.put(SDKConstants.param_txnAmt, Util.conversionCentAmount(order.getPrice()));
  params.put("orderDesc", order.getSubject());
  break;
case CONSUME:
  params.put(SDKConstants.param_txnAmt, Util.conversionCentAmount(order.getPrice()));
  params.put(SDKConstants.param_qrNo, order.getAuthCode());
  break;
case APPLY_QR_CODE:
  if (null != order.getPrice()){
    params.put(SDKConstants.param_txnAmt, Util.conversionCentAmount(order.getPrice()));

代码示例来源:origin: egzosn/pay-java-parent

/**
 * 将字节数组转换为十六进制字符数组
 *
 * @param data byte[]
 * @return 十六进制char[]
 */
public static char[] encodeHex(byte[] data) {
  return encodeHex(data, true);
}

代码示例来源:origin: egzosn/pay-java-parent

bizContent.put("subject", order.getSubject());
bizContent.put("out_trade_no", order.getOutTradeNo());
bizContent.put("total_amount", Util.conversionAmount(order.getPrice()).toString());
switch ((AliTransactionType) order.getTransactionType()) {
  case PAGE:

代码示例来源:origin: egzosn/pay-java-parent

/**
 * 申请退款接口
 *
 * @param refundOrder   退款订单信息
 * @return 返回支付方申请退款后的结果
 */
@Override
public Map<String, Object> refund(RefundOrder refundOrder) {
  //获取公共参数
  Map<String, Object> parameters = getPublicParameters();
  setParameters(parameters, "transaction_id", refundOrder.getTradeNo());
  setParameters(parameters, "out_trade_no", refundOrder.getOutTradeNo());
  setParameters(parameters, "out_refund_no", refundOrder.getRefundNo());
  parameters.put("total_fee", Util.conversionCentAmount(refundOrder.getTotalAmount()));
  parameters.put("refund_fee", Util.conversionCentAmount(refundOrder.getRefundAmount()));
  parameters.put("op_user_id", payConfigStorage.getPid());
  //设置签名
  setSign(parameters);
  return requestTemplate.postForObject(getUrl(WxTransactionType.REFUND), XML.getMap2Xml(parameters), JSONObject.class);
}

代码示例来源:origin: egzosn/pay-java-parent

/**
 * 将字节数组转换为十六进制字符串
 *
 * @param data     byte[]
 * @param toDigits 用于控制输出的char[]
 * @return 十六进制String
 */
protected static String encodeHexString(byte[] data, char[] toDigits) {
  return new String(encodeHex(data, toDigits));
}

代码示例来源:origin: egzosn/pay-java-parent

/**
 * 转账
 *
 * @param order 转账订单
 * @return 对应的转账结果
 */
@Override
public Map<String, Object> transfer(TransferOrder order) {
  //获取公共参数
  Map<String, Object> parameters = getPublicParameters(AliTransactionType.TRANS);
  Map<String, Object> bizContent = new TreeMap<String, Object>();
  bizContent.put("out_biz_no", order.getOutNo());
  //默认 支付宝登录号,支持邮箱和手机号格式。
  bizContent.put("payee_type", "ALIPAY_LOGONID");
  if (null != order.getTransferType()) {
    bizContent.put("payee_type", order.getTransferType().getType());
  }
  bizContent.put("payee_account", order.getPayeeAccount());
  bizContent.put("amount", Util.conversionAmount(order.getAmount()));
  bizContent.put("payer_show_name", order.getPayerName());
  bizContent.put("payee_real_name", order.getPayeeName());
  bizContent.put("remark", order.getRemark());
  //设置请求参数的集合
  parameters.put(BIZ_CONTENT, JSON.toJSONString(bizContent));
  //设置签名
  setSign(parameters);
  return getHttpRequestTemplate().postForObject(getReqUrl() + "?" + UriVariables.getMapToParameters(parameters), null, JSONObject.class);
}

代码示例来源:origin: egzosn/pay-java-parent

/**
   * 消费撤销/退货接口
   *
   * @param refundOrder 退款订单信息
   * @param type        UnionTransactionType.REFUND  或者UnionTransactionType.CONSUME_UNDO
   * @return 返回支付方申请退款后的结果
   */
  public Map<String, Object> unionRefundOrConsumeUndo(RefundOrder refundOrder, UnionTransactionType type) {
    Map<String, Object> params = this.getCommonParam();
    type.convertMap(params);
    params.put(SDKConstants.param_orderId, refundOrder.getRefundNo());
    params.put(SDKConstants.param_txnAmt, Util.conversionCentAmount(refundOrder.getRefundAmount()));
    params.put(SDKConstants.param_origQryId, refundOrder.getTradeNo());
    this.setSign(params);
    String responseStr = getHttpRequestTemplate().postForObject(this.getBackTransUrl(), params, String.class);
    JSONObject response = UriVariables.getParametersToMap(responseStr);
    if (this.verify(response)) {
      if (SDKConstants.OK_RESP_CODE.equals(response.getString(SDKConstants.param_respCode))) {
//                String origRespCode = response.getString(SDKConstants.param_origRespCode);
        //交易成功,更新商户订单状态
        //TODO
        return response;

      }
      throw new PayErrorException(new PayException(response.getString(SDKConstants.param_respCode), response.getString(SDKConstants.param_respMsg), response.toJSONString()));
    }
    throw new PayErrorException(new PayException("failure", "验证签名失败", response.toJSONString()));
  }

代码示例来源:origin: egzosn/pay-java-parent

/**
 * 申请退款接口
 *
 * @param refundOrder 退款订单信息
 * @return 返回支付方申请退款后的结果
 */
@Override
public Map<String, Object> refund(RefundOrder refundOrder) {
  //获取公共参数
  Map<String, Object> parameters = getPublicParameters(AliTransactionType.REFUND);
  Map<String, Object> bizContent = getBizContent(refundOrder.getTradeNo(), refundOrder.getOutTradeNo(), null);
  if (!StringUtils.isEmpty(refundOrder.getRefundNo())) {
    bizContent.put("out_request_no", refundOrder.getRefundNo());
  }
  bizContent.put("refund_amount", Util.conversionAmount(refundOrder.getRefundAmount()));
  //设置请求参数的集合
  parameters.put(BIZ_CONTENT, JSON.toJSONString(bizContent));
  //设置签名
  setSign(parameters);
  return requestTemplate.getForObject(getReqUrl() + "?" + UriVariables.getMapToParameters(parameters), JSONObject.class);
}

代码示例来源:origin: egzosn/pay-java-parent

parameters.put("spbill_create_ip", StringUtils.isEmpty(order.getSpbillCreateIp()) ? "192.168.1.150" : order.getSpbillCreateIp() );
parameters.put("total_fee", Util.conversionCentAmount( order.getPrice()));
if (StringUtils.isNotEmpty(order.getAddition())){
  parameters.put("attach", order.getAddition());

相关文章