php實現(xiàn)微信中的企業(yè)付款到零錢的完整教程

2023-03-14    分類: 網(wǎng)站建設(shè)

如果需要轉(zhuǎn)賬到用戶的零錢里,需要先獲取用戶的open_id,也就是在公眾號里登錄過并保存的open_id,然后就可以實現(xiàn)企業(yè)付款到零錢的功能了,以下是代碼詳解:
public function index(){
$transfer['payment_id'] = '201803221552123458';//訂單號,可以自定義,但不能重復(fù)使用
$transfer['open_id'] = session('login_weixin');//用戶的open_id
$transfer['real_name'] ='張三';//用戶的真實姓名
$transfer['amount'] = 0.3;//要付款的金額;
$this->dotransfer($transfer);//調(diào)用接口
}
/*
* 付款給用戶的接口(直接調(diào)用即可完成付款)
* */
public function dotransfer($transfer,&$msg=''){
$url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";
$parameters = array(
'mch_appid' => C('APPID'),//綁定支付的APPID
'mchid' => C('MCHID'),//商戶號
'nonce_str' => $this->create_noncestr(32), //生成32位的隨機(jī)字符串,見圖1
'partner_trade_no' => $transfer['payment_id'], //商戶訂單號,不能重復(fù)使用
'openid' => $transfer['open_id'],//用戶的open_id
'check_name' => 'OPTION_CHECK',//是否檢查姓名
're_user_name' => $transfer['real_name'], //真實姓名
'amount' => bcmul($transfer['amount'],100,0), //企業(yè)付款金額,單位為分 最低1元
'desc' => '分銷提現(xiàn)',//備注
'spbill_create_ip' => strval($_SERVER['SERVER_ADDR']),//服務(wù)器IP
);
$parameters['sign'] = $this->getSign($parameters, C('KEY'));//getSign函數(shù)見圖2,C('KEY'):商戶支付密鑰
$xml = $this->arrayToXml($parameters);//函數(shù)見圖3
$response = $this->postXmlCurl($xml, $url,true);//函數(shù)見圖4
$result = $this->xmlToArray($response);//函數(shù)見圖片5
if($result['return_code']=='SUCCESS'){
if($result['result_code']=='SUCCESS'){
$this->success($transfer['payment_id'].'=payment_id 付款成功');
return true;
}else{
$this->error($result['err_code_des'].' 付款失敗');
return false;
}
}else{
$this->error('付款失敗,微信接口出現(xiàn)異常');
return false;
}
}
企業(yè)付款php代碼1
圖1
微信企業(yè)付款php代碼2
圖2
微信企業(yè)付款php代碼3
圖3
微信企業(yè)付款php代碼4
圖4
微信企業(yè)付款php代碼5
圖5
微信企業(yè)付款php代碼6
圖6
作者:創(chuàng)新互聯(lián)陳應(yīng)信
創(chuàng)新互聯(lián)致力于為客戶定制互聯(lián)網(wǎng)解決方案,可以根據(jù)客戶需求定制系統(tǒng)功能,包括網(wǎng)站、小程序、APP等。

網(wǎng)頁題目:php實現(xiàn)微信中的企業(yè)付款到零錢的完整教程
本文路徑:http://www.bm7419.com/news10/244060.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣、做網(wǎng)站、響應(yīng)式網(wǎng)站域名注冊、關(guān)鍵詞優(yōu)化微信公眾號

廣告

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

營銷型網(wǎng)站建設(shè)