woocommerce关于第三方支付接口汇付天下对接的知识点总结

2023-11-17 13:43:47 浏览数 (1)

前言

这个支付接口的加密方式是rsa密钥形式。比其他的一般是md5形式稍微麻烦一点。

rsa加密代码

代码语言:javascript复制
            //组织签名串
            $kq_all_para=$this->param_ck_null($return_url,"pageUrl");
                $kq_all_para.=$this->param_ck_null($notify_url,'bgUrl');
                $kq_all_para.=$this->param_ck_null($MerchantNo,'merchantAcctId');
                $kq_all_para.=$this->param_ck_null($terminalId,'terminalId');
                $kq_all_para.=$this->param_ck_null($customerId,'customerId');
                $kq_all_para.=$this->param_ck_null($mref,'orderId');
                $kq_all_para.=$this->param_ck_null($amountcents,'orderAmount');
                $kq_all_para.=$this->param_ck_null($orderTime,'orderTime');
                $kq_all_para.=$this->param_ck_null($product_desc,'productDesc');
                $kq_all_para.=$this->param_ck_null($ext1,'ext1');
                $kq_all_para.=$this->param_ck_null($ext2,'ext2');
                $kq_all_para.=$this->param_ck_null($deviceType,'deviceType');
                $kq_all_para.=$this->param_ck_null($payType,'payType');

                $kq_all_para=substr($kq_all_para,0,strlen($kq_all_para)-1);

            //获取私钥
            $fp = fopen(__DIR__."/"."10020230621.key", "r");
                $priv_key = fread($fp, filesize(__DIR__."/".'10020230621.key'));
                fclose($fp);
                $pkeyid = openssl_get_privatekey($priv_key);

                // compute signature
                openssl_sign($kq_all_para, $signMsg, $pkeyid,OPENSSL_ALGO_SHA1);

                // free the key from memory
                openssl_free_key($pkeyid);

                        $checksum = base64_encode($signMsg);
                        $Body["signMsg"] = $checksum;

param_ck_null函数

用来拼接加密字符串函数

代码语言:javascript复制
        //拼接字符串
        public function param_ck_null($kq_va,$kq_na) {
                    if($kq_va == ""){
                            $kq_va="";
                    }else{
                        return $kq_va=$kq_na.'='.$kq_va.'&';
                    }
        }

0 人点赞