コード例 #1
0
ファイル: ThirdApi.java プロジェクト: noikiy/projects
  /** 调用翼支付接口进行支付 */
  public String bestPay(int taskId, int supportMoney) throws Exception {
    // 保存用户提交的订单
    TaskSupport support = new TaskSupport();
    support.setUserId(userRepository.findOne(Context.getCurrentUserId()));
    support.setTaskId(taskRepository.findOne(taskId));
    support.setSupportMoney(new BigDecimal(supportMoney));
    support.setCreatedTime(new Timestamp(System.currentTimeMillis()));
    taskSupportRepository.save(support);

    // 保存orders
    Orders order = new Orders();
    order.setOrderseq(BestPayUtils.doORDERSEQ());
    order.setOrderreqtranseq(BestPayUtils.doORDERREQTRANSEQ());
    order.setStatus(0);
    order.setTaskSupportId(support.getId());
    order.setCreatedTime(new Timestamp(System.currentTimeMillis()));
    ordersRepository.save(order);

    List<NameValuePair> parameters = new ArrayList<NameValuePair>();
    parameters.add(new BasicNameValuePair("MERCHANTID", BestPayConfig.MERCHANTID));
    parameters.add(new BasicNameValuePair("SUBMERCHANTID", BestPayConfig.SUBMERCHANTID));
    parameters.add(new BasicNameValuePair("ORDERSEQ", order.getOrderseq()));
    parameters.add(new BasicNameValuePair("ORDERREQTRANSEQ", order.getOrderreqtranseq()));
    parameters.add(
        new BasicNameValuePair("ORDERDATE", BestPayUtils.doORDERDATE(order.getCreatedTime())));
    parameters.add(
        new BasicNameValuePair("ORDERAMOUNT", new DecimalFormat("0.00").format(supportMoney) + ""));
    parameters.add(
        new BasicNameValuePair(
            "PRODUCTAMOUNT", new DecimalFormat("0.00").format(supportMoney) + ""));
    parameters.add(new BasicNameValuePair("ATTACHAMOUNT", BestPayConfig.ATTACHAMOUNT));
    parameters.add(new BasicNameValuePair("CURTYPE", BestPayConfig.CURTYPE));
    parameters.add(new BasicNameValuePair("ENCODETYPE", BestPayConfig.ENCODETYPE));
    parameters.add(new BasicNameValuePair("MERCHANTURL", BestPayConfig.MERCHANTURL));
    parameters.add(new BasicNameValuePair("BACKMERCHANTURL", BestPayConfig.BACKMERCHANTURL));
    parameters.add(new BasicNameValuePair("ATTACH", BestPayConfig.ATTACH));
    parameters.add(new BasicNameValuePair("BUSICODE", BestPayConfig.BUSICODE));
    parameters.add(new BasicNameValuePair("PRODUCTID", BestPayConfig.PRODUCTID));
    parameters.add(new BasicNameValuePair("TMNUM", BestPayConfig.TMNUM));
    parameters.add(new BasicNameValuePair("CUSTOMERID", BestPayConfig.CUSTOMERID));
    parameters.add(new BasicNameValuePair("PRODUCTDESC", BestPayConfig.PRODUCTDESC));
    parameters.add(new BasicNameValuePair("DIVDETAILS", BestPayConfig.DIVDETAILS));
    parameters.add(
        new BasicNameValuePair(
            "MAC",
            CryptTool.md5Digest(
                "MERCHANTID="
                    + BestPayConfig.MERCHANTID
                    + "&ORDERSEQ="
                    + order.getOrderseq()
                    + "&ORDERDATE="
                    + BestPayUtils.doORDERDATE(order.getCreatedTime())
                    + "&ORDERAMOUNT="
                    + new DecimalFormat("0.00").format(supportMoney)
                    + "&KEY="
                    + BestPayConfig.KEY)));

    HttpResult result =
        HttpConnectionManager.doPost("https://wappaywg.bestpay.com.cn/payWap.do", parameters);
    return result.getMessage();
  }
コード例 #2
0
ファイル: ThirdApi.java プロジェクト: noikiy/projects
 /**
  * 接受翼支付传回数据
  *
  * @return
  * @throws Exception
  */
 public String bestPayNotify(Map<String, String[]> params) throws Exception {
   if (params != null) {
     Map<String, String> doParams = new HashMap<String, String>();
     for (Iterator<String> iter = params.keySet().iterator(); iter.hasNext(); ) {
       String name = (String) iter.next();
       String[] values = (String[]) params.get(name);
       String valueStr = "";
       for (int i = 0; i < values.length; i++) {
         valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
       }
       doParams.put(name, valueStr);
     }
     // 翼支付网关平台交易流水号
     String UPTRANSEQ = "";
     if (doParams.containsKey("UPTRANSEQ")) {
       UPTRANSEQ = doParams.get("UPTRANSEQ");
       Logger.debug("", "UPTRANSEQ:" + UPTRANSEQ);
     }
     String TRANDATE = "";
     if (doParams.containsKey("TRANDATE")) {
       // 翼支付返回日期
       TRANDATE = doParams.get("TRANDATE");
       Logger.debug("", "TRANDATE:" + TRANDATE);
     }
     String RETNCODE = "";
     if (doParams.containsKey("RETNCODE")) {
       // 翼支付返回状态码
       RETNCODE = doParams.get("RETNCODE");
       Logger.debug("", "RETNCODE:" + RETNCODE);
     }
     String RETNINFO = "";
     if (doParams.containsKey("RETNINFO")) {
       RETNINFO = doParams.get("RETNINFO");
       Logger.debug("", "RETNINFO:" + RETNINFO);
     }
     String ORDERREQTRANSEQ = "";
     if (doParams.containsKey("ORDERREQTRANSEQ")) {
       ORDERREQTRANSEQ = doParams.get("ORDERREQTRANSEQ");
       Logger.debug("", "ORDERREQTRANSEQ:" + ORDERREQTRANSEQ);
     }
     String ORDERSEQ = "";
     if (doParams.containsKey("ORDERSEQ")) {
       ORDERSEQ = doParams.get("ORDERSEQ");
       Logger.debug("", "ORDERSEQ:" + ORDERSEQ);
     }
     String ORDERAMOUNT = "";
     if (doParams.containsKey("ORDERAMOUNT")) {
       ORDERAMOUNT = doParams.get("ORDERAMOUNT");
       Logger.debug("", "ORDERAMOUNT:" + ORDERAMOUNT);
     }
     String SIGN = doParams.get("SIGN");
     if (doParams.get("ENCODETYPE").equals("1")) {
       String MAC =
           CryptTool.md5Digest(
               "UPTRANSEQ="
                   + UPTRANSEQ
                   + "&MERCHANTID="
                   + BestPayConfig.MERCHANTID
                   + "&ORDERSEQ="
                   + ORDERSEQ
                   + "&ORDERAMOUNT="
                   + ORDERAMOUNT
                   + "&RETNCODE="
                   + RETNCODE
                   + "&RETNINFO="
                   + RETNINFO
                   + "&TRANDATE="
                   + TRANDATE
                   + "&KEY="
                   + BestPayConfig.KEY);
       if (MAC.equals(SIGN)) {
         // 校验成功 更改订单的状态 变为已支付
         Orders order = ordersRepository.get(ORDERSEQ, ORDERREQTRANSEQ);
         if (order != null) {
           order.setStatus(1);
           order.setUptranseq(UPTRANSEQ);
           order.setTrandate(TRANDATE);
           order.setRetncode(RETNCODE);
           order.setRetninfo(RETNINFO);
           order.setSign(SIGN);
           order.setModifiedTime(new Timestamp(System.currentTimeMillis()));
           ordersRepository.save(order);
           // 支付成功 创建支付评论
           TaskSupport taskSupport = taskSupportRepository.findOne(order.getTaskSupportId());
           if (taskSupport != null) {
             Comment comment = new Comment();
             Task task = taskSupport.getTaskId();
             comment.setTaskId(task);
             User user = taskSupport.getUserId();
             comment.setUserId(user);
             comment.setContent(user.getNickName() + "支持了" + taskSupport.getSupportMoney() + "元。");
             comment.setType(CommentType.SUPPORT.ordinal());
             comment.setStatus(CommentStatusType.VALID.ordinal());
             comment.setCreatedTime(new Timestamp(System.currentTimeMillis()));
             commentRepository.save(comment);
           }
           return "UPTRANSEQ_" + UPTRANSEQ;
         }
       } else {
         Logger.error(LOG_TAG, "MAC:" + MAC + " 和SIGN:" + SIGN + "不匹配!!!");
       }
     }
   }
   return "";
 }