java實(shí)現(xiàn)微信企業(yè)付款到個(gè)人
微信企業(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); //公眾賬號(hào)appid
parm.put("mchid", MCH_ID); //商戶號(hào)
parm.put("nonce_str", PayUtil.getNonceStr()); //隨機(jī)字符串
parm.put("partner_trade_no", PayUtil.getTransferNo()); //商戶訂單號(hào)
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", "測(cè)試轉(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)賬訂單號(hào)
transferMap.put("payment_no", restmap.get("payment_no")); //微信訂單號(hào)
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)賬訂單號(hào)
* @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)賬訂單號(hào)不能為空", 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)賬訂單號(hào)
transferMap.put("openid", restmap.get("openid")); //收款微信號(hào)
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í)際很簡(jiǎn)單,需要自己看一下文檔。
源代碼地址:微信企業(yè)付款
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
java簡(jiǎn)單網(wǎng)頁(yè)抓取的實(shí)現(xiàn)方法
這篇文章主要介紹了java簡(jiǎn)單網(wǎng)頁(yè)抓取的實(shí)現(xiàn)方法,詳細(xì)分析了與Java網(wǎng)頁(yè)抓取相關(guān)的tcp及URL相關(guān)概念,以及對(duì)應(yīng)的類文件原理,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2014-12-12
java集合框架的體系結(jié)構(gòu)詳細(xì)說(shuō)明
最近在一本J2EE的書中看到了很不錯(cuò)的對(duì)集合框架的說(shuō)明文章2012-11-11
Springboot應(yīng)用gradle?Plugin示例詳解
這篇文章主要介紹了Springboot應(yīng)用gradle?Plugin詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-04-04
Java多線程Thread基礎(chǔ)學(xué)習(xí)
每一個(gè)正在執(zhí)行的程序都是一個(gè)進(jìn)程,資源只有一塊,所以在同一時(shí)間段會(huì)有多個(gè)程序同時(shí)執(zhí)行,但是在一個(gè)時(shí)間點(diǎn)上,只能由一個(gè)程序執(zhí)行,多線程是在一個(gè)進(jìn)程的基礎(chǔ)之上的進(jìn)一步劃分,需要的朋友可以參考下2023-04-04
選擇Spring Boot項(xiàng)目的內(nèi)嵌容器的理由
Spring Boot是由Pivotal團(tuán)隊(duì)提供的全新框架,其設(shè)計(jì)目的是用來(lái)簡(jiǎn)化新Spring應(yīng)用的初始搭建以及開發(fā)過(guò)程。這篇文章主要介紹了選擇Spring Boot項(xiàng)目的內(nèi)嵌容器,需要的朋友可以參考下2017-11-11
JAVA Spring Boot 自動(dòng)配置實(shí)現(xiàn)原理詳解
這篇文章主要介紹了詳解SpringBoot自動(dòng)配置原理,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2021-09-09
Java實(shí)現(xiàn)讀取163郵箱,qq郵箱的郵件內(nèi)容
這篇文章主要利用Java語(yǔ)言實(shí)現(xiàn)讀取163郵箱和qq郵箱的郵件內(nèi)容,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起動(dòng)手試一試2022-02-02

