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

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

成都創(chuàng)新互聯(lián)長(zhǎng)期為超過千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為革吉企業(yè)提供專業(yè)的成都網(wǎng)站制作、成都網(wǎng)站建設(shè)、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)革吉網(wǎng)站改版等技術(shù)服務(wù)。擁有十載豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。

企業(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等

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

支付功能

包含企業(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ì)將金額支付到用戶余額中

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

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

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

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

本文標(biāo)題:java實(shí)現(xiàn)微信企業(yè)付款到個(gè)人
URL分享:http://muchs.cn/article24/isjgce.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷、企業(yè)建站微信小程序、網(wǎng)站內(nèi)鏈、建站公司App設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)