话不多说 直接上代码
/**
* 企业转账
* @return
*/
public function qiyezhuanzhang($order_sn,$total_fee,$bossfind,$openid,$order_id)
{
// 获取配置项
$this->config['APPID'] = $bossfind['jsappid'];
$this->config['MCHID'] = $bossfind['jsmchid'];
$this->config['KEY'] = $bossfind['jskey'];
$weixinpay_config = $this->config;
// 订单数据 请根据订单号out_trade_no 从数据库中查出实际的body、total_fee、out_trade_no、product_id
$data = array(
'desc' => $bossfind['app_name'],// 商品描述(需要根据自己的业务修改)
'amount' => $total_fee*100,// 订单金额 以(分)为单位(需要根据自己的业务修改)
'partner_trade_no' => $order_sn,// 订单号(需要根据自己的业务修改)
'openid' => $openid,// 获取到的openid
'check_name' => 'NO_CHECK',// NO_CHECK:不校验真实姓名 FORCE_CHECK:强校验真实姓名
're_user_name' => '王小二',// 真实姓名
'mch_appid' => $weixinpay_config['APPID'],
'mchid' => $weixinpay_config['MCHID'],
'nonce_str' => md5(time() . '!@#$%^&*()_+'),
'spbill_create_ip' => '192.168.0.1',
);
// 生成签名
$sign = $this->makeSignss($data,$weixinpay_config['KEY']);
$data['sign'] = $sign;
// var_dump($data);exit;
$xml = $this->toXml_tui($data);
// var_dump($xml);exit;
$url = 'https://api.mch.weixin.qq.com/secapi/pay/refund';//接收xml数据的文件
$header[] = "Content-type: text/xml,charset:utf-8";//定义content-type为xml,注意是数组
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 兼容本地没有指定curl.cainfo路径的错误
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
//证书的使用
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');
curl_setopt($ch, CURLOPT_SSLCERT, './cert/apiclient_cert.pem');
curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');
curl_setopt($ch, CURLOPT_SSLKEY, './cert/apiclient_key.pem');
$response = curl_exec($ch);
if (curl_errno($ch)) {
// 显示报错信息;终止继续执行
die(curl_error($ch));
}
curl_close($ch);
$result = $this->toArray($response);
// 显示错误信息
if ($result['return_code'] == 'FAIL') {
die($result['return_msg']);
}
return $result;
}