PHP micro-channel merchant payment companies pay to change function

The opening of a condition that we must first set up in a micro-channel platform.

The following micro-channel documents in there, I'm here probably swept some of the more important.

Payment of funds

Corporate Payment to change the balance of funds of funds business number.

 

According to the account number of the merchant to open the case, the real money accounts do have differences:

Under ◆ By default, the companies pay to use business change basic account number (or the balance of the account) balance. As business operations has opened an account number, the payment business to change the use of funds in the operating account.

◆ basic account (or such other dispensing account) sources of funding, may be trading settlement funds (basic account only), or funds to the account recharge. When money is less than the account balance, payment will be due to lack of balance and payment failure.

Payment Rules

payment method

 ◆ Support API interface or web operation, payment to the target user.

Receivables specified user identity

 ◆ by APPID + OPENID user specified collection.

 ◆ APPID need to apply for a merchant when APPID number, or have a binding relationship with the business number.

 ◆ OPENID the acquisition mode, can refer to: https: //mp.weixin.qq.com/wiki t = resource / res_main & id = mp1421140839?

Payment amount

 ◆ does not support non-real-name user to fight money

 ◆ to a real-name user pays the same, single daily limit of 2W / 2W

 ◆ the same day a merchant 100W total payout limit

 

Note: The above rules limit 2w, 100w because of calculation rules and risk control strategies, not entirely accurate value, the amount for reference only, please do not rely on this money handling system should be based on the interface and the actual return query results prevail, Please know.

Receivables user identity verification

 ◆ target user payments, provide verifiable real name of the function

Query payments

 ◆ paid a record company can view the data through the enterprise payment queries, or queries merchant number of funds flowing water.

Payment frequency

 ◆ default of payment up to 10 times a day to the same user, can be set in the security business platform --API

Other Considerations

 ◆ payment amount must be less than or equal to the amount of current available balance of the merchant;

 

Two interface address

Interface link: https: //api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers

Request parameters:

Referring specifically to the development of official business payment documentation

PHP代码示例调用,这里是写在一个文件里,看每个方法就知道是干嘛用的咯。

 

<?php
//企业付款到微信零钱,PHP接口调用方法
define("APPID", "wx875439864"); //商户账号appid
define("MCHID", "190023450990"); // 商户号
define("SECRECT_KEY", "145535866885");  //支付密钥签名
define("IP", "120.178.12.52");   //IP

function createNoncestr($length =32) 
{
    $chars = "abcdefghijklmnopqrstuvwxyz0123456789";  
    $str ="";
    for ( $i = 0; $i < $length; $i++ )  {  
        $str.= substr($chars, mt_rand(0, strlen($chars)-1), 1);  
    }  
    return $str;
}

function unicode() {
    $str = uniqid(mt_rand(),1);
    $str=sha1($str);
    return md5($str);
}
function arraytoxml($data){
    $str='<xml>';
    foreach($data as $k=>$v) {
        $str.='<'.$k.'>'.$v.'</'.$k.'>';
    }
    $str.='</xml>';
    return $str;
}
function xmltoarray($xml) { 
    //禁止引用外部xml实体 
    libxml_disable_entity_loader(true); 
    $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); 
    $val = json_decode(json_encode($xmlstring),true); 
    return $val;
} 

function curl($param="",$url) {
    $postUrl = $url;
    $curlPost = $param;
    $ch = curl_init();                                      //初始化curl
    curl_setopt($ch, CURLOPT_URL,$postUrl);                 //抓取指定网页
    curl_setopt($ch, CURLOPT_HEADER, 0);                    //设置header
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);            //要求结果为字符串且输出到屏幕上
    curl_setopt($ch, CURLOPT_POST, 1);                      //post提交方式
    curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);           // 增加 HTTP Header(头)里的字段 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);        // 终止从服务端进行验证
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch,CURLOPT_SSLCERT,ROOT_PATH .'/wxpay/cacert/apiclient_cert.pem'); //这个是证书的位置绝对路径
    curl_setopt($ch,CURLOPT_SSLKEY,ROOT_PATH .'/wxpay/cacert/apiclient_key.pem'); //这个也是证书的位置绝对路径
    $data = curl_exec($ch);                                 //运行curl
    curl_close($ch);
    return $data;
}

/*
$amount 发送的金额(分)目前发送金额不能少于1元
$re_openid, 发送人的 openid
$desc  //  企业付款描述信息 (必填)
$check_name    收款用户姓名 (选填)
*/
function sendMoney($amount,$re_openid,$desc='测试',$check_name=''){

    $total_amount = (100) * $amount;

    $data=array(
        'mch_appid'=>APPID,//商户账号appid
        'mchid'=> MCHID,//商户号
        'nonce_str'=>createNoncestr(),//随机字符串
        'partner_trade_no'=> date('YmdHis').rand(1000, 9999),//商户订单号
        'openid'=> $re_openid,//用户openid
        'check_name'=>'NO_CHECK',//校验用户姓名选项,
        're_user_name'=> $check_name,//收款用户姓名
        'amount'=>$total_amount,//金额
        'desc'=> $desc,//企业付款描述信息
        'spbill_create_ip'=> IP,//Ip地址
    );
    $secrect_key=SECRECT_KEY;///这个就是个API密码。MD5 32位。
    $data=array_filter($data);
    ksort($data);
    $str='';
    foreach($data as $k=>$v) {
       $str.=$k.'='.$v.'&';
    }
    $str.='key='.$secrect_key;
    $data['sign']=md5($str);
    $xml=arraytoxml($data);

    $url='https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers'; //调用接口
    $res=curl($xml,$url);
    $return=xmltoarray($res);


    print_r($return);
    //返回来的结果
    // [return_code] => SUCCESS [return_msg] => Array ( ) [mch_appid] => wxd44b890e61f72c63 [mchid] => 1493475512 [nonce_str] => 616615516 [result_code] => SUCCESS [partner_trade_no] => 20186505080216815 
    // [payment_no] => 1000018361251805057502564679 [payment_time] => 2018-05-15 15:29:50


    $responseObj = simplexml_load_string($res, 'SimpleXMLElement', LIBXML_NOCDATA);
    echo $res= $responseObj->return_code;  //SUCCESS  如果返回来SUCCESS,则发生成功,处理自己的逻辑

    return $res;
}

?>

三 调用方法  :

直接在你写的方法里调用此方法就好了

sendMoney(1,'ewrwexe32423423423423423','xxxx测试');

返回的结果,成功的话就直接print出来,失败的话也要抛出异常。如果你还是不懂,请查看之前分享过的这篇文章。

微信企业付款到个人零钱功能,很简单的就实现咯!

效果图如下

转自“php自学中心 - PHP微信商户支付企业付款到零钱功能

 

Guess you like

Origin www.cnblogs.com/zxf100/p/11130509.html