~~~
<?PHP
namespace app\common\library;
class WxV3Pay
{
//微信支付批次单号查询批次单API
public function get_transfer($batch_id)
{
$merchant_id = \think\Config::get("site.merchant_id");//服务商 商户号
$serial_no = \think\Config::get("site.serial_no");//API证书序列号
$url = 'https://api.mch.weixin.qq.com/v3/partner-transfer/batches/batch-id/' . $batch_id . '?need_query_detail=false&offset=1';
$sign = $this->get_Sign($url, "GET", '', $this->get_Privatekeyfu(), $merchant_id, $serial_no);//$http_method要大写
$header[] = 'User-Agent:https://zh.wikipedia.org/wiki/User_agent';
$header[] = 'Accept:application/json';
$header[] = 'Content-Type:application/json';
$header[] = 'Authorization:WECHATPAY2-SHA256-RSA2048 ' . $sign;
$back = $this->http_Request($url, $header);
return $back;
}
//微信支付明细单号查询明细单API
public function get_wxmingxi($batch_id,$detail_id)
{
$merchant_id = \think\Config::get("site.merchant_id");//服务商 商户号
$serial_no = \think\Config::get("site.serial_no");//API证书序列号
$url = 'https://api.mch.weixin.qq.com/v3/partner-transfer/batches/batch-id/' . $batch_id . '/details/detail-id/' . $detail_id . '';
$sign = $this->get_Sign($url, "GET", '', $this->get_Privatekeyfu(), $merchant_id, $serial_no);//$http_method要大写
$header[] = 'User-Agent:https://zh.wikipedia.org/wiki/User_agent';
$header[] = 'Accept:application/json';
$header[] = 'Content-Type:application/json';
$header[] = 'Authorization:WECHATPAY2-SHA256-RSA2048 ' . $sign;
$back = $this->http_Request($url, $header);
return $back;
}
//商家批次单号查询批次单API
public function get_sjpici($outbatchno)
{
$merchant_id = \think\Config::get("site.merchant_id");//服务商 商户号
$serial_no = \think\Config::get("site.serial_no");//API证书序列号
$url = 'https://api.mch.weixin.qq.com/v3/partner-transfer/batches/out-batch-no/' . $outbatchno . '?need_query_detail=false&offset=0';
$sign = $this->get_Sign($url, "GET", '', $this->get_Privatekeyfu(), $merchant_id, $serial_no);//$http_method要大写
$header[] = 'User-Agent:https://zh.wikipedia.org/wiki/User_agent';
$header[] = 'Accept:application/json';
$header[] = 'Content-Type:application/json';
$header[] = 'Authorization:WECHATPAY2-SHA256-RSA2048 ' . $sign;
$back = $this->http_Request($url, $header);
return $back;
}
//商家明细单号查询明细单API
public function get_sjmingxi($outbatchno,$outdetailno)
{
$merchant_id = \think\Config::get("site.merchant_id");//服务商 商户号
$serial_no = \think\Config::get("site.serial_no");//API证书序列号
$url = 'https://api.mch.weixin.qq.com/v3/partner-transfer/batches/out-batch-no/' . $outbatchno . '/details/out-detail-no/' . $outdetailno . '';
$sign = $this->get_Sign($url, "GET", '', $this->get_Privatekeyfu(), $merchant_id, $serial_no);//$http_method要大写
$header[] = 'User-Agent:https://zh.wikipedia.org/wiki/User_agent';
$header[] = 'Accept:application/json';
$header[] = 'Content-Type:application/json';
$header[] = 'Authorization:WECHATPAY2-SHA256-RSA2048 ' . $sign;
$back = $this->http_Request($url, $header);
return $back;
}
//余额查询
/**
* @param string $account_type BASIC 基本账户 OPERATION运营账户
* @return bool|string
*/
public function get_cha($mac_id,$account_type="OPERATION")
{
$merchant_id = \think\Config::get("site.merchant_id");//服务商 商户号
$serial_no = \think\Config::get("site.serial_no");//API证书序列号
$url = 'https://api.mch.weixin.qq.com/v3/ecommerce/fund/balance/'.$mac_id.'?account_type='.$account_type;
$sign = $this->get_Sign($url, "GET", '', $this->get_Privatekeyfu(), $merchant_id, $serial_no);//$http_method要大写
$header[] = 'User-Agent:https://zh.wikipedia.org/wiki/User_agent';
$header[] = 'Accept:application/json';
$header[] = 'Content-Type:application/json';
$header[] = 'Authorization:WECHATPAY2-SHA256-RSA2048 ' . $sign;
$back = $this->http_Request($url, $header);
return $back;
}
/**
* 批量转账 资金授权模式
*/
public function get_sedf()
{
$data = [
'sub_mchid' => "xxxx",
'authorization_type' => 'FUND_AUTHORIZATION_TYPE',
'out_batch_no' => 'xxxxxx',
'batch_name' => '工资',
'batch_remark' => '工资',
'total_amount' => 100,
'total_num' => 1,
'transfer_detail_list' => [
['out_detail_no' => 'xxxx',
'transfer_amount' => 100,
'transfer_remark' => '测试',
'openid' => 'xxxxx',
]
],
'sp_appid' => 'xxxxx'
];
$merchant_id = \think\Config::get("site.merchant_id");//服务商 商户号
$serial_no = \think\Config::get("site.serial_no");//API证书序列号
$sign = $this->get_Sign("https://api.mch.weixin.qq.com/v3/partner-transfer/batches", "POST", json_encode($data), $this->get_Privatekey(), $merchant_id, $serial_no);//$http_method要大写
$header[] = 'User-Agent:https://zh.wikipedia.org/wiki/User_agent';
$header[] = 'Accept:application/json';
$header[] = 'Content-Type:application/json';
$header[] = 'Authorization:WECHATPAY2-SHA256-RSA2048 ' . $sign;
$back = $this->http_Request("https://api.mch.weixin.qq.com/v3/partner-transfer/batches", $header, json_encode($data));
return $back;
}
/**
* 批量转账 资金+信息 授权模式
*/
public function get_sedfxinxi($payData)
{
$sp_appid=\think\Config::get("site.sp_appid");
$sub_appid=\think\Config::get("site.sub_appid");
$AesUtil= new AesUtil("paipailaowu");
$data=[
'sub_mchid' => $payData['sub_mchid'],
'sub_appid' => $sub_appid,
'sp_appid' => $sp_appid,
'authorization_type' => 'INFORMATION_AND_FUND_AUTHORIZATION_TYPE',
'out_batch_no' => $payData['out_batch_no'],
'batch_name' => $payData['batch_name'],
'batch_remark' => $payData['batch_remark'],
'total_amount' =>$payData['total_amount']*100,
'total_num' => $payData['total_num'],
];
foreach ($payData['transfer_detail_list'] as $k=>$v){
$data['transfer_detail_list'][]=[
'out_detail_no'=>$v['out_detail_no'],
'transfer_amount'=>$v['transfer_amount']*100,
'transfer_remark'=>$v['transfer_remark'],
'openid' => $v['openid'],
'user_name'=>$AesUtil->getEncrypt($v['user_name']),
];
}
$merchant_id = \think\Config::get("site.merchant_id");//服务商 商户号
$serial_no = \think\Config::get("site.serial_no");//API证书序列号
$sign = $this->get_Sign("https://api.mch.weixin.qq.com/v3/partner-transfer/batches", "POST", json_encode($data), $this->get_Privatekey(), $merchant_id, $serial_no);//$http_method要大写
$header[] = 'User-Agent:https://zh.wikipedia.org/wiki/User_agent';
$header[] = 'Accept:application/json';
$header[] = 'Content-Type:application/json';
$header[] = 'Authorization:WECHATPAY2-SHA256-RSA2048 ' . $sign;
$serial_nos=$this->get_Certificates();
$serial_nos=json_decode($serial_nos,true);
$header[] = 'Wechatpay-Serial:' . $serial_nos['data'][0]['serial_no'];
$back = $this->http_Request("https://api.mch.weixin.qq.com/v3/partner-transfer/batches", $header, json_encode($data));
return $back;
}
/**
* 获取平台证书内容
*/
public function get_Certificates()
{
$merchant_id = \think\Config::get("site.merchant_id");//服务商 商户号
$serial_no = \think\Config::get("site.serial_no");//API证书序列号
$sign = $this->get_Sign("https://api.mch.weixin.qq.com/v3/certificates", "GET", "", $this->get_Privatekeyfu(), $merchant_id, $serial_no);//$http_method要大写
$header[] = 'User-Agent:https://zh.wikipedia.org/wiki/User_agent';
$header[] = 'Accept:application/json';
$header[] = 'Authorization:WECHATPAY2-SHA256-RSA2048 ' . $sign;
$back = $this->http_Request("https://api.mch.weixin.qq.com/v3/certificates", $header);
return $back;
}
/**
* 获取平台证书内容
*/
public function get_Certificatesfu()
{
$merchant_id = \think\Config::get("site.merchant_id");//服务商 商户号
$serial_no = \think\Config::get("site.serial_no");//API证书序列号
$sign = $this->get_Sign("https://api.mch.weixin.qq.com/v3/certificates", "GET", "", $this->get_Privatekeyfu(), $merchant_id, $serial_no);//$http_method要大写
$header[] = 'User-Agent:https://zh.wikipedia.org/wiki/User_agent';
$header[] = 'Accept:application/json';
$header[] = 'Authorization:WECHATPAY2-SHA256-RSA2048 ' . $sign;
$back = $this->http_Request("https://api.mch.weixin.qq.com/v3/certificates", $header);
return $back;
}
public function get_Signs()
{
$merchant_id = \think\Config::get("site.merchant_id");//服务商 商户号
$serial_no = \think\Config::get("site.serial_no");//API证书序列号
$sign = $this->get_Sign("https://api.mch.weixin.qq.com/v3/certificates", "GET", "", $this->get_Privatekeyfu(), $merchant_id, $serial_no);
return $sign;
}
/**
* 获取sign
* @param $url
* @param $http_method [POST GET 必读大写]
* @param $body [请求报文主体(必须进行json编码)]
* @param $mch_private_key [商户私钥]
* @param $merchant_id [商户号]
* @param $serial_no [证书编号]
* @return string
*/
private function get_Sign($url, $http_method, $body, $mch_private_key, $merchant_id, $serial_no)
{
$timestamp = time();//时间戳
$nonce = $timestamp . rand(10000, 99999);//随机字符串
$url_parts = parse_url($url);
$canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : ""));
$message =
$http_method . "\n" .
$canonical_url . "\n" .
$timestamp . "\n" .
$nonce . "\n" .
$body . "\n";
openssl_sign($message, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption');
$sign = base64_encode($raw_sign);
$token = sprintf('mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"',
$merchant_id, $nonce, $timestamp, $serial_no, $sign);
return $token;
}
/**
* 获取商户私钥
* @return false|resource
*/
public function get_Privatekey()
{
$Privatekey = \think\Config::get("site.Privatekey");//服务商 商户号
$mch_private_key = openssl_get_privatekey(file_get_contents(ROOT_PATH . "/public" .$Privatekey));//获取私钥
return $mch_private_key;
}
public function get_Privatekeyfu()
{
$Privatekey = \think\Config::get("site.Privatekey");//服务商 商户号
$mch_private_key = openssl_get_privatekey(file_get_contents(ROOT_PATH . "/public" .$Privatekey));//获取私钥
return $mch_private_key;
}
/**
* 数据请求
* @param $url
* @param array $header 获取头部
* @param string $post_data POST数据,不填写默认以GET方式请求
* @return bool|string
*/
public function http_Request($url, $header = array(), $post_data = "")
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 2);
if ($post_data != "") {
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); //设置post提交数据
}
//判断当前是不是有post数据的发
$output = curl_exec($ch);
if ($output === FALSE) {
$output = "curl 错误信息: " . curl_error($ch);
}
curl_close($ch);
return $output;
}
}
?>
~~~
- 面试
- php
- laravel
- 安装
- 创建数据
- 创建控制器
- 错误
- 权限认证
- 图形验证码
- 管理员
- 无限分类
- 视频播放
- 推流
- pc页面
- thinkphp5
- 表单提交安全验证
- crontab
- 获取下级所有数据
- 过滤敏感词
- 二维码
- 邀请码
- jwt token
- 笛卡尔
- 高并发解决优化
- 设置多语言
- 计算经纬度两点距离
- 分片上传
- centos swoole
- 查看swoole版本
- centos 安装 redis
- 把整数随机分成n份或者红包
- 生成随机字符串
- 获取上级
- 宝塔搭建nginx推拉流
- 生成二维码海报
- 二维数组去重
- 经纬度 ---边距 和判断是不是范围内
- workerman
- 扩展
- redis
- mysql
- mysql 主从复制
- 定位问题语句
- 列的选择规则
- Enum介绍
- 索引介绍
- 延迟关联
- in 查询陷阱
- limit 优化
- 事务
- 读写分离
- mysql 权限错误
- mysql计算距离
- mysql数据导出导入
- 索引失效
- mysql 语句技巧
- linux
- 配置nginx 高可用
- Nginx内核参数优化
- 配置优化
- nginx-keepalived实现高可用负载
- lvs+keepalived
- centos5关闭防火墙
- nginx操作
- linux操作
- mysql 安装
- php
- 安装phpadmin
- php7安装mongodb
- 查看php位置
- 查找开启的进程端口
- 守护进程
- centos安装php7.2
- centos 错误解决
- 安装php7错误
- mysql 错误
- 支付宝支付
- html
- js 倒计时
- go vscode 配置
- go util
- 获取两个数之间随机数
- java
- lambda
- 随机抽取
- lombok
- springboot
- 常见注解
- 接受参数常用注解
- 文件上传
- 上传错误日志拦截
- 拦截器
- 定时任务
- mybatis
- 关联查询
- 全局配置
- 缓存
- git
- 微信相关
- 体现到零钱
- 服务商转账
- 公众号小程序相关
- 小程序二维码
- svn
- layui