欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java實(shí)現(xiàn)微信企業(yè)付款到個(gè)人

 更新時(shí)間:2018年10月02日 10:18:22   作者:Andyzty  
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)微信企業(yè)付款到個(gè)人功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

微信企業(yè)付款到個(gè)人的PHP實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下

企業(yè)付款實(shí)現(xiàn)企業(yè)向個(gè)人付款,實(shí)現(xiàn)付款到用戶零錢。項(xiàng)目實(shí)現(xiàn)了企業(yè)付款到個(gè)人和企業(yè)付款個(gè)人賬單查詢。代碼包括簽名實(shí)現(xiàn),雙向證書驗(yàn)證,付款功能等

支付流程

付款功能

企業(yè)付款到授權(quán)用戶的零錢

企業(yè)付款注意注意:
1、所有接口需要雙向證書驗(yàn)證
2、需要設(shè)置接口秘鑰,簽名用

詳細(xì)參考:微信企業(yè)付款開發(fā)文檔

項(xiàng)目結(jié)構(gòu)

和上一篇一樣,需要配置證書以及商戶id、appid等

支付功能

包含企業(yè)轉(zhuǎn)賬和企業(yè)轉(zhuǎn)賬查詢

package org.andy.wxpay.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.andy.wxpay.model.JsonResult;
import org.andy.wxpay.model.ResponseData;
import org.andy.wxpay.utils.CollectionUtil;
import org.andy.wxpay.utils.ConfigUtil;
import org.andy.wxpay.utils.HttpUtils;
import org.andy.wxpay.utils.PayUtil;
import org.andy.wxpay.utils.SerializerFeatureUtil;
import org.andy.wxpay.utils.StringUtil;
import org.andy.wxpay.utils.WebUtil;
import org.andy.wxpay.utils.XmlUtil;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.fastjson.JSON;

/**
 * 創(chuàng)建時(shí)間:2016年11月9日 下午5:49:00
 * 
 * @author andy
 * @version 2.2
 */

@Controller
@RequestMapping("/transfer")
public class TransferController {

 private static final Logger LOG = Logger.getLogger(TransferController.class);

 private static final String TRANSFERS_PAY = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"; // 企業(yè)付款

 private static final String TRANSFERS_PAY_QUERY = "https://api.mch.weixin.qq.com/mmpaymkttransfers/gettransferinfo"; // 企業(yè)付款查詢

 private static final String APP_ID = ConfigUtil.getProperty("wx.appid");

 private static final String MCH_ID = ConfigUtil.getProperty("wx.mchid");

 private static final String API_SECRET = ConfigUtil.getProperty("wx.api.secret");

 /**
 * 企業(yè)向個(gè)人支付轉(zhuǎn)賬
 * @param request
 * @param response
 * @param openid 用戶openid
 * @param callback
 */
 @RequestMapping(value = "/pay", method = RequestMethod.POST)
 public void transferPay(HttpServletRequest request, HttpServletResponse response, String openid, String callback) {
 LOG.info("[/transfer/pay]");
 //業(yè)務(wù)判斷 openid是否有收款資格

 Map<String, String> restmap = null;
 try {
  Map<String, String> parm = new HashMap<String, String>();
  parm.put("mch_appid", APP_ID); //公眾賬號appid
  parm.put("mchid", MCH_ID); //商戶號
  parm.put("nonce_str", PayUtil.getNonceStr()); //隨機(jī)字符串
  parm.put("partner_trade_no", PayUtil.getTransferNo()); //商戶訂單號
  parm.put("openid", openid); //用戶openid 
  parm.put("check_name", "NO_CHECK"); //校驗(yàn)用戶姓名選項(xiàng) OPTION_CHECK
  //parm.put("re_user_name", "安迪"); //check_name設(shè)置為FORCE_CHECK或OPTION_CHECK,則必填
  parm.put("amount", "100"); //轉(zhuǎn)賬金額
  parm.put("desc", "測試轉(zhuǎn)賬到個(gè)人"); //企業(yè)付款描述信息
  parm.put("spbill_create_ip", PayUtil.getLocalIp(request)); //服務(wù)器Ip地址
  parm.put("sign", PayUtil.getSign(parm, API_SECRET));

  String restxml = HttpUtils.posts(TRANSFERS_PAY, XmlUtil.xmlFormat(parm, false));
  restmap = XmlUtil.xmlParse(restxml);
 } catch (Exception e) {
  LOG.error(e.getMessage(), e);
 }

 if (CollectionUtil.isNotEmpty(restmap) && "SUCCESS".equals(restmap.get("result_code"))) {
  LOG.info("轉(zhuǎn)賬成功:" + restmap.get("err_code") + ":" + restmap.get("err_code_des"));
  Map<String, String> transferMap = new HashMap<>();
  transferMap.put("partner_trade_no", restmap.get("partner_trade_no"));//商戶轉(zhuǎn)賬訂單號
  transferMap.put("payment_no", restmap.get("payment_no")); //微信訂單號
  transferMap.put("payment_time", restmap.get("payment_time")); //微信支付成功時(shí)間
  WebUtil.response(response,
   WebUtil.packJsonp(callback,
    JSON.toJSONString(new JsonResult(1, "轉(zhuǎn)賬成功", new ResponseData(null, transferMap)),
     SerializerFeatureUtil.FEATURES)));
 }else {
  if (CollectionUtil.isNotEmpty(restmap)) {
  LOG.info("轉(zhuǎn)賬失?。? + restmap.get("err_code") + ":" + restmap.get("err_code_des"));
  }
  WebUtil.response(response, WebUtil.packJsonp(callback, JSON
   .toJSONString(new JsonResult(-1, "轉(zhuǎn)賬失敗", new ResponseData()), SerializerFeatureUtil.FEATURES)));
 }
 }

 /**
 * 企業(yè)向個(gè)人轉(zhuǎn)賬查詢
 * @param request
 * @param response
 * @param tradeno 商戶轉(zhuǎn)賬訂單號
 * @param callback
 */
 @RequestMapping(value = "/pay/query", method = RequestMethod.POST)
 public void orderPayQuery(HttpServletRequest request, HttpServletResponse response, String tradeno,
  String callback) {
 LOG.info("[/transfer/pay/query]");
 if (StringUtil.isEmpty(tradeno)) {
  WebUtil.response(response, WebUtil.packJsonp(callback, JSON
   .toJSONString(new JsonResult(-1, "轉(zhuǎn)賬訂單號不能為空", new ResponseData()), SerializerFeatureUtil.FEATURES)));
 }

 Map<String, String> restmap = null;
 try {
  Map<String, String> parm = new HashMap<String, String>();
  parm.put("appid", APP_ID);
  parm.put("mch_id", MCH_ID);
  parm.put("partner_trade_no", tradeno);
  parm.put("nonce_str", PayUtil.getNonceStr());
  parm.put("sign", PayUtil.getSign(parm, API_SECRET));

  String restxml = HttpUtils.posts(TRANSFERS_PAY_QUERY, XmlUtil.xmlFormat(parm, true));
  restmap = XmlUtil.xmlParse(restxml);
 } catch (Exception e) {
  LOG.error(e.getMessage(), e);
 }

 if (CollectionUtil.isNotEmpty(restmap) && "SUCCESS".equals(restmap.get("result_code"))) {
  // 訂單查詢成功 處理業(yè)務(wù)邏輯
  LOG.info("訂單查詢:訂單" + restmap.get("partner_trade_no") + "支付成功");
  Map<String, String> transferMap = new HashMap<>();
  transferMap.put("partner_trade_no", restmap.get("partner_trade_no"));//商戶轉(zhuǎn)賬訂單號
  transferMap.put("openid", restmap.get("openid")); //收款微信號
  transferMap.put("payment_amount", restmap.get("payment_amount")); //轉(zhuǎn)賬金額
  transferMap.put("transfer_time", restmap.get("transfer_time")); //轉(zhuǎn)賬時(shí)間
  transferMap.put("desc", restmap.get("desc")); //轉(zhuǎn)賬描述
  WebUtil.response(response, WebUtil.packJsonp(callback, JSON
   .toJSONString(new JsonResult(1, "訂單轉(zhuǎn)賬成功", new ResponseData(null, transferMap)), SerializerFeatureUtil.FEATURES)));
 }else {
  if (CollectionUtil.isNotEmpty(restmap)) {
  LOG.info("訂單轉(zhuǎn)賬失?。? + restmap.get("err_code") + ":" + restmap.get("err_code_des"));
  }
  WebUtil.response(response, WebUtil.packJsonp(callback, JSON
   .toJSONString(new JsonResult(-1, "訂單轉(zhuǎn)賬失敗", new ResponseData()), SerializerFeatureUtil.FEATURES)));
 }
 }

}

其他代碼參考上一篇 微信支付-App支付服務(wù)端詳解

支付結(jié)果

支付成功后會(huì)將金額支付到用戶余額中

功能實(shí)際很簡單,需要自己看一下文檔。

源代碼地址:微信企業(yè)付款

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java實(shí)現(xiàn)合并多個(gè)升序鏈表

    Java實(shí)現(xiàn)合并多個(gè)升序鏈表

    本文主要介紹了Java實(shí)現(xiàn)合并多個(gè)升序鏈表,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • Spring Security使用中Preflight請求和跨域問題詳解

    Spring Security使用中Preflight請求和跨域問題詳解

    這篇文章主要給大家介紹了關(guān)于Spring Security使用中Preflight請求和跨域問題的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-11-11
  • Hibernate一對多關(guān)聯(lián)雙向關(guān)聯(lián)代碼實(shí)現(xiàn)分享

    Hibernate一對多關(guān)聯(lián)雙向關(guān)聯(lián)代碼實(shí)現(xiàn)分享

    Hibernate一對多關(guān)聯(lián)雙向關(guān)聯(lián)代碼實(shí)現(xiàn)分享,大家參考使用吧
    2013-12-12
  • 通過實(shí)例解析Java分布式鎖三種實(shí)現(xiàn)方法

    通過實(shí)例解析Java分布式鎖三種實(shí)現(xiàn)方法

    這篇文章主要介紹了通過實(shí)例解析Java分布式鎖三種實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-07-07
  • SpringBoot@Componet注解注入失敗的問題

    SpringBoot@Componet注解注入失敗的問題

    這篇文章主要介紹了SpringBoot@Componet注解注入失敗的問題及解決,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • Java高并發(fā)測試框架JCStress詳解

    Java高并發(fā)測試框架JCStress詳解

    這篇文章主要介紹了Java高并發(fā)測試框架JCStress,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • 使用Spring安全表達(dá)式控制系統(tǒng)功能訪問權(quán)限問題

    使用Spring安全表達(dá)式控制系統(tǒng)功能訪問權(quán)限問題

    從spring security 3.0開始已經(jīng)可以使用spring Expression表達(dá)式來控制授權(quán),允許在表達(dá)式中使用復(fù)雜的布爾邏輯來控制訪問的權(quán)限。這篇文章主要介紹了使用Spring安全表達(dá)式控制系統(tǒng)功能訪問權(quán)限,需要的朋友可以參考下
    2019-11-11
  • SpringBoot 啟動(dòng)報(bào)錯(cuò)Unable to connect to Redis server: 127.0.0.1/127.0.0.1:6379問題的解決方案

    SpringBoot 啟動(dòng)報(bào)錯(cuò)Unable to connect to 

    這篇文章主要介紹了SpringBoot 啟動(dòng)報(bào)錯(cuò)Unable to connect to Redis server: 127.0.0.1/127.0.0.1:6379問題的解決方案,文中通過圖文結(jié)合的方式給大家講解的非常詳細(xì),對大家解決問題有一定的幫助,需要的朋友可以參考下
    2024-10-10
  • Java中ConcurrentHashMap是如何實(shí)現(xiàn)線程安全

    Java中ConcurrentHashMap是如何實(shí)現(xiàn)線程安全

    ConcurrentHashMap是一個(gè)哈希表,支持檢索的全并發(fā)和更新的高預(yù)期并發(fā)。本文主要介紹了Java中ConcurrentHashMap是如何實(shí)現(xiàn)線程安全,感興趣的可以了解一下
    2021-11-11
  • SpringBoot中的@DependsOn注解詳解

    SpringBoot中的@DependsOn注解詳解

    這篇文章主要介紹了SpringBoot中的@DependsOn注解詳解,
    2023-08-08

最新評論