微信企業(yè)付款到個(gè)人的PHP實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
成都創(chuàng)新互聯(lián)長期為超過千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為革吉企業(yè)提供專業(yè)的成都網(wǎng)站制作、成都網(wǎng)站建設(shè)、外貿(mào)營銷網(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等
支付功能
包含企業(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是否有收款資格 Maprestmap = null; try { Map parm = new HashMap (); 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 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 restmap = null; try { Map parm = new HashMap (); 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 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í)際很簡單,需要自己看一下文檔。
源代碼地址:微信企業(yè)付款
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。