未封装的退款
<?php
// +----------------------------------------------------------------------
// | Tplay [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://tplay.pengyichen.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 听雨 < 389625819@qq.com >
// +----------------------------------------------------------------------
//app\api\controller、Test
namespace app\api\controller;
use think\Validate;
use WePay\Order;
use think\Db;
class Test
{
// $config = array(
// 'appid' => 'wxb108ecfd7a6a4205',
// 'app_secret' => '7d50b25808df0677d75f47ce68f388bb',
// 'pay_mchid' => '1519396251', // 微信支付MCHID 商户收款账号
// 'pay_apikey' => 'klfdye2rcea0zzeukglx1v1p0k0a3swo', // 微信支付KEY
// 'notify_url' => 'https://www.mySercver.com/WxApi/Pay/notify', // 接收支付状态的连接
// // 微信使用code换取用户openid及session_key的url地址
// 'login_url' => "https://api.weixin.qq.com/sns/jscode2session?" .
// "appid=wxb108ecfd7a6a4205&secret=7d50b25808df0677d75f47ce68f388bb&js_code=".$js_code."&grant_type=authorization_code",
// );
//api/Test/ttt
// ttt($total_fee,$order_sn)
public function ttt($total_fee,$order_sn)
{
$data = request()->param();
// $order_sn = 'GP442320210418231312';
$refund_fee= $total_fee ;
if ($refund_fee){
//$out_refund_no 商户退款单号 自定义而已
$out_refund_no = 'refund'.time();
//统一下单退款参数构造
$unifiedorder = array(
'appid' => 'KL392520210418231504',
'mch_id' => '1607696586',
'nonce_str' => self::getNonceStr(),
'out_trade_no' => $order_sn, //商户订单号 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。
'out_refund_no' => $out_refund_no, //商户退款单号 商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。
'total_fee' => intval($total_fee*100), //订单金额
'refund_fee' => intval(floatval($refund_fee*100)), //退款金额
);
// return self::getNonceStr().'---$out_trade_no---'.$out_trade_no.'---$out_refund_no---'.$out_refund_no.'---$total_fee---'.$total_fee.'---$refund_fee---'.$refund_fee;
$unifiedorder['sign'] = self::makeSign($unifiedorder);
// return $unifiedorder['sign'];
//请求数据
$xmldata = self::array2xml($unifiedorder);
$opUrl = "https://api.mch.weixin.qq.com/secapi/pay/refund";
$res = self::curl_post_ssl_refund($opUrl, $xmldata);
if (!$res) {
self::return_err("Can't connect the server");
}
$content = self::xml2array($res);
if (strval($content['result_code']) == 'FAIL') {
return $content['err_code_des'];
self::return_err(strval($content['err_code_des']));
}
if (strval($content['return_code']) == 'FAIL') {
return $content['return_msg'];
self::return_err(strval($content['return_msg']));
}
return '退款成功!';
}else{
return '不符合退款订单!';
}
}
//---------------------------------------------------------------用到的函数------------------------------------------------------------
/**
* 此方法是为了进行 微信退款操作的 专属定制哦
* (嘁,其实就是照搬了 人家官方的PHP Demo代码咯)
* TODO 尤其注意代码中涉及到的 "证书使用方式(二选一)"
* TODO 证书的路径要求为 服务器中的绝对路径[我的服务器为 CentOS6.5]
* TODO 证书是 在微信支付开发文档中有所提及,可自行获取保存
*/
protected function curl_post_ssl_refund($url, $vars, $second=30,$aHeader=array())
{
$ch = curl_init();
//超时时间
curl_setopt($ch,CURLOPT_TIMEOUT,$second);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
//这里设置代理,如果有的话
//curl_setopt($ch,CURLOPT_PROXY, '10.206.30.98');
//curl_setopt($ch,CURLOPT_PROXYPORT, 8080);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
//TODO 以下两种方式需选择一种
/*------- --第一种方法,cert 与 key 分别属于两个.pem文件--------------------------------*/
//默认格式为PEM,可以注释
//curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
curl_setopt($ch,CURLOPT_SSLCERT,'./wxzs/apiclient_cert.pem');
//默认格式为PEM,可以注释
//curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
curl_setopt($ch,CURLOPT_SSLKEY,'./wxzs/apiclient_key.pem');
/**
* 补充 当找不到ca根证书的时候还需要rootca.pem文件
* TODO 注意,微信给出的压缩包中,有提示信息:
* 由于绝大部分操作系统已内置了微信支付服务器证书的根CA证书,
* 2018年3月6日后, 不再提供CA证书文件(rootca.pem)下载
*/
//curl_setopt($ch, CURLOPT_CAINFO,'/mnt/www/Public/certxxxxxxxxxxxxxxxxxxxx755/rootca.pem');
/*----------第二种方式,两个文件合成一个.pem文件----------------------------------------*/
//curl_setopt($ch,CURLOPT_SSLCERT,getcwd().'/all.pem');
if( count($aHeader) >= 1 ){
curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);
}
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$vars);
$data = curl_exec($ch);
if($data){
curl_close($ch);
return $data;
}
else {
$error = curl_errno($ch);
//echo "call faild, errorCode:$error\n";
curl_close($ch);
return false;
}
}
/**
* 错误返回提示
* @param string $errMsg 错误信息
* @param string $status 错误码
* @return json的数据
*/
protected function return_err($errMsg = 'error', $status = 0)
{
// exit(json_encode(array('status' => $status, 'result' => 'fail', 'errmsg' => $errMsg)));
}
/**
* 正确返回
* @param array $data 要返回的数组
* @return json的数据
*/
protected function return_data($data = array())
{
exit(json_encode(array('status' => 1, 'result' => 'success', 'data' => $data)));
}
/**
* 将一个数组转换为 XML 结构的字符串
* @param array $arr 要转换的数组
* @param int $level 节点层级, 1 为 Root.
* @return string XML 结构的字符串
*/
protected function array2xml($arr, $level = 1)
{
$s = $level == 1 ? "<xml>" : '';
foreach ($arr as $tagname => $value) {
if (is_numeric($tagname)) {
$tagname = $value['TagName'];
unset($value['TagName']);
}
if (!is_array($value)) {
$s .= "<{$tagname}>" . (!is_numeric($value) ? '<![CDATA[' : '') . $value . (!is_numeric($value) ? ']]>' : '') . "</{$tagname}>";
} else {
$s .= "<{$tagname}>" . $this->array2xml($value, $level + 1) . "</{$tagname}>";
}
}
$s = preg_replace("/([\x01-\x08\x0b-\x0c\x0e-\x1f])+/", ' ', $s);
return $level == 1 ? $s . "</xml>" : $s;
}
/**
* 将xml转为array
* @param string $xml xml字符串
* @return array 转换得到的数组
*/
protected function xml2array($xml)
{
//禁止引用外部xml实体
libxml_disable_entity_loader(true);
$result = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $result;
}
/**
*
* 产生随机字符串,不长于32位
* @param int $length
* @return 产生的随机字符串
*/
protected function getNonceStr($length = 32)
{
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
/**
* 生成签名
* @return 签名
*/
protected function makeSign($data)
{
//获取微信支付秘钥
$key = 'e10adc3949ba59abbe56e057f20f883e';
// 去空
$data = array_filter($data);
//签名步骤一:按字典序排序参数
ksort($data);
$string_a = http_build_query($data);
$string_a = urldecode($string_a);
//签名步骤二:在string后加入KEY
//$config=$this->config;
$string_sign_temp = $string_a . "&key=" . $key;
//签名步骤三:MD5加密
$sign = md5($string_sign_temp);
// 签名步骤四:所有字符转为大写
$result = strtoupper($sign);
return $result;
}
public function index()
{
$param = array('code'=>'215451');
$result = SendSms($param,'18716482623');
var_dump($result);
}
}
1、先建造一个公共方法、也可以用sdk中的代码
namespace app\api\controller;
class common
{
private $key = '';
/**********下方代码可以放到公共函数中**********/
/*
*
* 产生随机字符串,不长于32位
* @param int $length
* @return 产生的随机字符串
*/
p
public function getNonceStr($length = 32)
{
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
/*
* 生成签名
* @return 签名
*/
public function makeSign($data)
{
//获取微信支付秘钥
$key = $this->key ;
// 去空
$data = array_filter($data);
//签名步骤一:按字典序排序参数
ksort($data);
$string_a = http_build_query($data);
$string_a = urldecode($string_a);
//签名步骤二:在string后加入KEY
//$config=$this->config;
$string_sign_temp = $string_a . "&key=" . $key;
//签名步骤三:MD5加密
$sign = md5($string_sign_temp);
// 签名步骤四:所有字符转为大写
$result = strtoupper($sign);
return $result;
}
//将一个数组转换为 XML 结构的字符串
public function array2xml($arr, $level = 1)
{
$s = $level == 1 ? "<xml>" : "";
foreach ($arr as $tagname => $value) {
if (is_numeric($tagname)) {
$tagname = $value['TagName'];
unset($value["TagName"]);
}
if (!is_array($value)) {
$s .= "<{$tagname}>" . (!is_numeric($value) ? '<![CDATA[' : "") . $value . (!is_numeric($value) ? ']]>' : "") . "</{$tagname}>";
} else {
$s .= "<{$tagname}>" . $this->array2xml($value, $level + 1) . "</{$tagname}>";
}
}
$s = preg_replace("/([\x01-\x08\x0b-\x0c\x0e-\x1f])+/", ' ', $s);
return $level == 1 ? $s . "</xml>" : $s;
}
/*
* 将xml转为array
* @param string $xml xml字符串
* @return array 转换得到的数组
*/
public function xml2array($xml)
{
libxml_disable_entity_loader(true);
$result = json_decode(json_encode(simplexml_load_string($xml, "SimpleXMLElement", LIBXML_NOCDATA)), true);
return $result;
}
}
2、建立控制器进行退款
退款的curl需要证书、所以这里我们单独写在了控制器中
namespace app\api\controller;
class Wxrefund
{
private $appid = '';
private $mch_id = '';
private $apiclient_cert = './wx/apiclient_cert.pem';
private $apiclient_key = './wx/apiclient_key.pem';
/*
refund(支付订单号,支付总金额,退款金额)
*/
public function refund($order_sn,$total_fee,$refund_fee)
{
$data = request()->param();
if ($refund_fee){
$out_trade_no = $order_sn;//商户支付单号 自定义而已
$out_refund_no = 'refund'.time();//商户退款单号 自定义而已
$common=new common;//调用公共方法
//统一下单退款参数构造
$unifiedorder = array(
'appid' => $this->appid,//appid
'mch_id' => $this->mch_id,//商户id
'nonce_str' => $common->getNonceStr(),//公共方法的随机字符串
'out_trade_no' => $out_trade_no, //商户订单号
'out_refund_no' => $out_refund_no, //商户退款单号
'total_fee' => $total_fee, //订单金额 需要整数 依分为单位 所以一般*100
'refund_fee' => intval(floatval($refund_fee)), //退款金额 需要整数 依分为单位 所以一般*100
);
//生成签名并加入数组
$unifiedorder['sign'] = $common->makeSign($unifiedorder);
//根据数组转成xml生成请求数据
$xmldata = $common->array2xml($unifiedorder);
$opUrl = "https://api.mch.weixin.qq.com/secapi/pay/refund";
//吊起请求
$res = $this->curl_post_ssl_refund($opUrl, $xmldata);
if (!$res) {
return json_encode(array('status' => $status, 'result' => 'fail', 'errmsg' => "Can't connect the server"));
}
$content = $common->xml2array($res);
if (strval($content['result_code']) == "FAIL" ) {
return json_encode(array("status" => $status, "result" => 'fail', "errmsg" => strval($content["err_code_des"]))) ;
}
if (strval($content['return_code']) == "FAIL") {
return json_encode(array("status" => $status, "result" => "fail", "errmsg" => strval($content['return_msg']))) ;
}
return "退款成功!";
}else{
return "不符合退款订单!";
}
}
//curl
public function curl_post_ssl_refund($url, $vars, $second=30,$aHeader=array())
{
$ch = curl_init();
//超时时间
curl_setopt($ch,CURLOPT_TIMEOUT,$second);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
//这里设置代理,如果有的话
//curl_setopt($ch,CURLOPT_PROXY, "10.206.30.98");
//curl_setopt($ch,CURLOPT_PROXYPORT, 8080);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
//TODO 以下两种方式需选择一种
/*------- --第一种方法,cert 与 key 分别属于两个.pem文件--------------------------------*/
//默认格式为PEM,可以注释
//curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
curl_setopt($ch,CURLOPT_SSLCERT, $this->apiclient_cert); curl_setopt($ch,CURLOPT_SSLKEY, $this->apiclient_key);
//默认格式为PEM,可以注释
//curl_setopt($ch,CURLOPT_SSLKEYTYPE,"PEM");
//默认格式为PEM,可以注释
//curl_setopt($ch,CURLOPT_SSLKEYTYPE,"PEM");
/**
* 补充 当找不到ca根证书的时候还需要rootca.pem文件
* TODO 注意,微信给出的压缩包中,有提示信息:
* 由于绝大部分操作系统已内置了微信支付服务器证书的根CA证书,
* 2018年3月6日后, 不再提供CA证书文件(rootca.pem)下载
*/
/*----------第二种方式,两个文件合成一个.pem文件----------------------------------------*/
//curl_setopt($ch,CURLOPT_SSLCERT,getcwd().'/all.pem');
if( count($aHeader) >= 1 ){
curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);
}
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$vars);
$data = curl_exec($ch);
if($data){
curl_close($ch);
return $data;
}
else {
$error = curl_errno($ch);
//echo "call faild, errorCode:$error\n";
curl_close($ch);
return false;
}
}
}
3、提现·
https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_1
<?php
namespace real;
use real\WechatPay\WechatPayCommon;
//real\Wxrefund
/*
支付退款类
*/
class WechatWithdrawal{
private $appid = '';
private $mch_id = '';
private $key = '';
private $apiclient_cert = './wx/apiclient_cert.pem';
private $apiclient_key = './wx/apiclient_key.pem';
public function WechatWithdrawal($openId,$money) {
$pub = ['app_id'=>$this->appid,'mch_id'=>$this->mch_id,'key'=>$this->key];//config('keys.payConfig');
$appid = $pub['app_id'];//商户账号appid
$mch_id = $pub['mch_id'];//商户号
$key = $pub['key'];
$openid = $openId;//授权用户openid
$common=new \WechatPayCommon;//调用公共方法
$arr = array();
$arr['partner_trade_no'] = '123456789' . date("Ymd") . rand(10000, 90000) . rand(10000, 90000);//商户订单号
$arr['openid'] = $openid;
$arr['amount'] = $money * 100;//付款金额,单位为分
$arr['mch_appid'] = $appid;
$arr['mchid'] = $mch_id;
$arr['nonce_str'] = $common->getNonceStr();//公共方法的随机字符串
$arr['desc'] = "零钱提现";//描述信息
$arr['check_name'] = 'NO_CHECK';//是否验证用户真实姓名,这里不验证
// $arr['spbill_create_ip'] = 'xx.xx.xx.xx';//获取服务器的ip
//封装的关于签名的算法
$arr['sign'] = $common->makeSign($arr,$key);//签名
$var = $common->array2xml($arr);
// dump($arr['sign'] );exit;
$xml = $this->curl_post_ssl('https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers',$var,30, array(), 1);
libxml_disable_entity_loader(true);
//echo $xml; die;
$obj1=simplexml_load_string($xml,'SimpleXMLElement');
//var_dump($obj1); die;
$rdata = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)),true);
// var_dump('cash_xmldata',$rdata);//eblog('cash_xmldata',$rdata);
// dump($rdata);exit;
$return_code = trim(strtoupper($rdata['return_code']));
$result_code = trim(strtoupper($rdata['result_code']));
if ($return_code == 'SUCCESS' && $result_code == 'SUCCESS') {
$isrr = array(
'status'=>1,
'msg' => '',
);
} else {
// $returnmsg = $rdata['return_msg'];
$err_code_des = $rdata['err_code_des'];
$isrr = array(
'status' => 0,
'msg' => $err_code_des,
);
}
return $isrr;
}
protected function curl_post_ssl($url, $vars, $second = 30, $aHeader = array())
{
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_TIMEOUT, $second);//设置执行最长秒数
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// 终止从服务端进行验证
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');//证书类型
// curl_setopt($ch, CURLOPT_SSLCERT, $isdir . 'apiclient_cert.pem');//证书位置
// curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');//CURLOPT_SSLKEY中规定的私钥的加密类型
// curl_setopt($ch, CURLOPT_SSLKEY, $isdir . 'apiclient_key.pem');//证书位置
curl_setopt($ch,CURLOPT_SSLCERT, $this->apiclient_cert);
curl_setopt($ch,CURLOPT_SSLKEY, $this->apiclient_key);
// curl_setopt($ch, CURLOPT_CAINFO, 'PEM');
// curl_setopt($ch, CURLOPT_CAINFO, $isdir . 'rootca.pem');
if (count($aHeader) >= 1) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);//设置头部
}
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);//全部数据使用HTTP协议中的"POST"操作来发送
$data = curl_exec($ch);//执行回话
if ($data) {
curl_close($ch);
return $data;
} else {
$error = curl_errno($ch);
echo "call faild, errorCode:$error\n";
curl_close($ch);
return false;
}
}
}
原提现以舍弃
class Cash{
public function wxcash($openId,$money) {
$pub = ['app_id'=>'######','mch_id'=>'######','key'=>'######'];//config('keys.payConfig');
$appid = $pub['app_id'];//商户账号appid
$mch_id = $pub['mch_id'];//商户号
$key = $pub['key'];
$openid = $openId;//授权用户openid
$arr = array();
$arr['mch_appid'] = $appid;
$arr['mchid'] = $mch_id;
$arr['nonce_str'] = md5(uniqid(microtime(true),true));//随机字符串,不长于32位
$arr['partner_trade_no'] = '123456789' . date("Ymd") . rand(10000, 90000) . rand(10000, 90000);//商户订单号
$arr['openid'] = $openid;
$arr['check_name'] = 'NO_CHECK';//是否验证用户真实姓名,这里不验证
$arr['amount'] = $money * 100;//付款金额,单位为分
$arr['desc'] = "零钱提现";//描述信息
$arr['spbill_create_ip'] = 'xx.xx.xx.xx';//获取服务器的ip
//封装的关于签名的算法
$arr['sign'] = $this->makeSign($arr,$key);//签名
$var = $this->arrayToXml($arr);
// dump($arr['sign'] );exit;
$xml = $this->curl_post_ssl('https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers',$var,30, array(), 1);
libxml_disable_entity_loader(true);
//echo $xml; die;
$obj1=simplexml_load_string($xml,'SimpleXMLElement');
//var_dump($obj1); die;
$rdata = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)),true);
var_dump('cash_xmldata',$rdata);//eblog('cash_xmldata',$rdata);
// dump($rdata);exit;
$return_code = trim(strtoupper($rdata['return_code']));
$result_code = trim(strtoupper($rdata['result_code']));
if ($return_code == 'SUCCESS' && $result_code == 'SUCCESS') {
$isrr = array(
'status'=>1,
'msg' => '',
);
} else {
// $returnmsg = $rdata['return_msg'];
$err_code_des = $rdata['err_code_des'];
$isrr = array(
'status' => 0,
'msg' => $err_code_des,
);
}
return $isrr;
}
protected function makesign($data,$key)
{
//获取微信支付秘钥
$data = array_filter($data);
//签名步骤一:按字典序排序参数
ksort($data);
$string_a = http_build_query($data);
$string_a = urldecode($string_a);
//签名步骤二:在string后加入KEY
//$config=$this->config;
$string_sign_temp = $string_a."&key=".$key;
//签名步骤三:MD5加密
$sign = md5($string_sign_temp);
// 签名步骤四:所有字符转为大写
$result = strtoupper($sign);
// $result = strtoupper(hash_hmac("sha256",$string_sign_temp,$key));
return $result;
}
protected function arraytoxml($data){
$str='<xml>';
foreach($data as $k=>$v) {
$str.='<'.$k.'>'.$v.'</'.$k.'>';
}
$str.='</xml>';
return $str;
}
protected function curl_post_ssl($url, $vars, $second = 30, $aHeader = array())
{
$isdir = "cert/";//APP_PATH."/common/library/php_sdk/lib/";//证书位置
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_TIMEOUT, $second);//设置执行最长秒数
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// 终止从服务端进行验证
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');//证书类型
curl_setopt($ch, CURLOPT_SSLCERT, $isdir . 'apiclient_cert.pem');//证书位置
curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');//CURLOPT_SSLKEY中规定的私钥的加密类型
curl_setopt($ch, CURLOPT_SSLKEY, $isdir . 'apiclient_key.pem');//证书位置
curl_setopt($ch, CURLOPT_CAINFO, 'PEM');
curl_setopt($ch, CURLOPT_CAINFO, $isdir . 'rootca.pem');
if (count($aHeader) >= 1) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);//设置头部
}
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);//全部数据使用HTTP协议中的"POST"操作来发送
$data = curl_exec($ch);//执行回话
if ($data) {
curl_close($ch);
return $data;
} else {
$error = curl_errno($ch);
echo "call faild, errorCode:$error\n";
curl_close($ch);
return false;
}
}
}
$cash=new Cash();
$cash->wxcash({openid},0.01);