<?php namespace Wechat; use Wechat\Common; class Wxpaytochange{ private $check_name = 'FORCE_CHECK'; private $appid; private $mchid; private $key; private $sslcert_path; private $sslkey_path; private $error_code = ''; private $error_msg = ''; /** * 企业支付(零钱) * @param string $openid 用户openID * @param string $trade_no 单号 * @param string $money 金额 * @param string $desc 描述 * @return string XML 结构的字符串 */ public function __construct($options){ $this->appid = $options['appid']; $this->mchid = $options['mch_id']; $this->key = $options['key']; $this->sslcert_path = $options['sslcert_path']; $this->sslkey_path = $options['sslkey_path']; } public function pay($data){ $data = array( 'mch_appid' => $this->appid, 'mchid' => $this->mchid, 'nonce_str' => Common::getNonceStr(16), 'partner_trade_no' => $data['trade_no'], //商户订单号,需要唯一 'openid' => $data['openid'], 'check_name'=> $this->check_name, //OPTION_CHECK不强制校验真实姓名, FORCE_CHECK:强制 NO_CHECK: 're_user_name' => $data['real_name'], //收款人用户姓名 'amount' => $data['money'] * 100, //付款金额单位为分 'desc' => $data['desc'], 'spbill_create_ip' => Common::getIp() ); // var_dump($data); //生成签名 $data['sign'] = Common::MakeSign($data,$this->key); //构造XML数据 $xmldata = Common::array2xml($data); $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers'; //发送post请求 $res = Common::curl_post_ssl($url, $xmldata,$second=30,[],$this->sslcert_path,$this->sslkey_path); // var_dump($res); if(!$res){ return ['code'=>403, 'msg'=>"Can't connect the server"]; } //付款结果分析 $content = Common::xml2array($res); if($content['return_code'] == 'FAIL'){ return ['return_code'=>$content['return_code'], 'msg'=>$content['return_msg'],'err_code'=>$content['err_code'],'err_code_des'=>$content['err_code_des']]; } if($content['result_code'] == 'FAIL'){ return ['return_code'=>$content['err_code'], 'msg'=>$content['err_code_des'],'err_code'=>$content['err_code'],'err_code_des'=>$content['err_code_des']]; } $resdata = array( 'return_code' => $content['return_code'], 'result_code' => $content['result_code'], 'err_code' => $content['err_code'], 'err_code_des' => $content['err_code_des'], 'partner_trade_no' => $content['partner_trade_no'], 'payment_no' => $content['payment_no'], 'payment_time' => $content['payment_time'], ); return $resdata; } }
本文为看恩吧原创文章,转载无需和我联系,但请注明来自knsay.com