美文网首页
申请二级商户资金账单

申请二级商户资金账单

作者: 毕德申 | 来源:发表于2023-01-03 11:09 被阅读0次

//获取二级商户资金账单

    public function getecommercebill(Request $request){

        $bill_date=$request->input('bill_date');

        $account_type=$request->input('account_type');

        $algorithm=$request->input('algorithm');

        $url='https://api.mch.weixin.qq.com/v3/ecommerce/bill/fundflowbill?bill_date='.$bill_date.'&account_type='.$account_type.'&algorithm='.$algorithm;

        $merchant_id=config('wechat.payment.default.mch_id');//商户号

        $serial_no=config('wechat.payment.default.serial_no');//不是平台证书序列号

        $mch_private_key=$this->getPublicKey();//读取商户api证书公钥 getPublicKey()获取方法 见下文

        $timestamp=time();//时间戳

        $nonce=$this->nonce_str();//随机字符串

        $body="";

        $sign=$this->sign($url,'GET',$timestamp,$nonce,$body,$mch_private_key,$merchant_id,$serial_no);//签名

        $header=[

            'Authorization:WECHATPAY2-SHA256-RSA2048 ' . $sign,

            'Accept:application/json',

            'User-Agent:' . $merchant_id,

            'Content-Type:application/json',

            'Wechatpay-Serial:' . $this->getzhengshu()//获取平台证书序列号

        ];

        $result=$this->curl($url,'',$header,'GET');

        $res=json_decode($result,true);

        if(!array_key_exists('download_bill_list',$res)){

            Log::info($res);

            return $this->success($res);

        }

        Log::info($bill_date.'下载资金账单,页数为'.count($res['download_bill_list']));

        foreach($res['download_bill_list'] as $key=>$val){

            $ciphertext= $this->down($val['download_url']);

            $key=$this->getDecrypt($val['encrypt_key'],'',$val['nonce']);

            //下载账单文件,得到账单文件密文ciphertext,需要对密文进行base64编码,然后再进行解密。否则密文乱码,解密返回false  

$result_str=$this->decryptToString('',$val['nonce'],base64_encode($ciphertext),$key);

            $res_arr=$this->deal_ecommerce_bill($result_str);

    }

        return $this->success($res);

    }

public function down($url){

        $merchant_id=config('wechat.payment.default.mch_id');//商户号

        $serial_no=config('wechat.payment.default.serial_no');//不是平台证书序列号

        $mch_private_key=$this->getPublicKey();//读取商户api证书公钥 getPublicKey()获取方法 见下文

        $timestamp=time();//时间戳

        $nonce=$this->nonce_str();//随机字符串

        $body="";

        $sign=$this->sign($url,'GET',$timestamp,$nonce,$body,$mch_private_key,$merchant_id,$serial_no);//签名

        $header=[

            'Authorization:WECHATPAY2-SHA256-RSA2048 ' . $sign,

            'Accept:application/json',

            'User-Agent:' . $merchant_id,

            'Content-Type:application/json;charset=utf-8',

            'Wechatpay-Serial:' . $this->getzhengshu()//获取平台证书序列号

        ];

        $result=$this->curl($url,'',$header,'GET');

return $result;

}

//解密加密密钥

    public function getDecrypt($ciphertext, $associatedData, $nonceStr){

        $mch_private_key= file_get_contents(config('wechat.payment.default.key_path'));

//        Log::info($mch_private_key);

        $str = base64_decode($ciphertext);

        openssl_private_decrypt($str,$encrypted,$mch_private_key,OPENSSL_PKCS1_OAEP_PADDING);

        return trim($encrypted);

    }

    //解密返回的信息

    public function decryptToString($associatedData,$nonceStr,$ciphertext,$aesKey){

        if (strlen($aesKey) != 32) {

            throw new InvalidArgumentException('无效的ApiV3Key,长度应为32个字节');

        }

        $ciphertext=\base64_decode($ciphertext);

        if (strlen($ciphertext) <= 16) {

return false;

        }

        if (function_exists('\sodium_crypto_aead_aes256gcm_is_available') &&

            \sodium_crypto_aead_aes256gcm_is_available()) {

            return \sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $aesKey);

        }

        if (function_exists('\Sodium\crypto_aead_aes256gcm_is_available') &&

            \Sodium\crypto_aead_aes256gcm_is_available()) {

            return \Sodium\crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $aesKey);

        }

        if(PHP_VERSION_ID >= 70100 && in_array('aes-256-gcm', \openssl_get_cipher_methods())){

            $ctext=substr($ciphertext,0,-16);

            $authTag=substr($ciphertext,-16);

            return \openssl_decrypt(

                $ctext,

                'aes-256-gcm',

                $aesKey,

                \OPENSSL_RAW_DATA,

                $nonceStr,

                $authTag,

                $associatedData

            );

        }

        throw new \RuntimeException('php7.1');

    }

相关文章

  • 申请二级商户资金账单

    //获取二级商户资金账单 public function getecommercebill(Request $r...

  • 浅析微信支付:下载对账单和资金账单

    本文是【浅析微信支付】系列文章的第九篇,主要讲解商户下载对账单接口和资金账单接口的实现和一些注意事项。 浅析微信支...

  • 技术组件(三)-业务账单(自定文件模版)工具

    需求 灵活配置账单,10行代码批量生成商户账单. 场景概述 一个代理商,下面有n个收单商户,要生成下面每个收单商户...

  • 微信支付之特约商户申请管理

    微信支付之特约商户申请管理 特约商户申请管理 特约商户申请管理 - 微信商户平台 本文仅作为微信支付服务商平台中的...

  • 微信支付

    如何成为微信支付商户的方法: 腾讯客服-微信支付商户申请接入信息汇总:腾讯客服-微信支付商户申请接入信息汇总 腾讯...

  • 周记 2017 4.24 - 4.30

    微信支付宝对账单下载 背景:帮朋友下载商户在微信和支付宝每天的账单微信对账单API支付宝对账单API 微信对账单 ...

  • 饭卡商户后台文档

    状态码(state_code)解释 商户后台 管理员role = '1';普通商户role = '2'; 申请商户...

  • 小程序 微信支付遇到的问题

    1.商户号分为两种类型:一种是微信开放平台申请的商户号;一种是微信公号申请的商户号。微信开放平台的商户号,小程序支...

  • 陶吉明-网页后台产品原型

    这是为餐厅商户做的一个商户后台,主要解决商户接受并处理用户订单、账单查询与提现、餐厅信息管理于菜品管理的功能。

  • 项目申报员前景,你想要的答案都在这里

    项目申请专员主要负责组织申请公司各种政府扶持资金、行业支持专项资金、创新资金、科研资金、奖励资金、发展资金、资质申...

网友评论

      本文标题:申请二级商户资金账单

      本文链接:https://www.haomeiwen.com/subject/hlclcdtx.html