用AI赚第一桶💰低成本搭建一套AI赚钱工具,源码可二开。 广告
~~~ <?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; } } ?> ~~~