You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
3.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace yisheng;
class Base
{
//官方API文档 https://doc.eycard.cn/web/#/285?page_id=4149
protected $config; //付呗配置
protected $url = 'https://t-wapi.bhecard.com:8443'; //请求网关
protected $baseUrl = 'https://t-wapi.bhecard.com:8443'; //请求网关(jsapi下单)
protected $baseUrlLedger = 'https://t-wapi.bhecard.com:6111'; //请求网关(分账,退货)
protected $cashierUrl = 'https://mtest.eycard.cn:4443'; //添加商户
protected $key = 'jucheng'; //付呗配置
//被扫支付 https://t-wapi.bhecard.com:8443/standard/scanPay
//jsapi下单https://t-wapi.bhecard.com:8443/standard/jsapi
//单笔查询 https://t-wapi.bhecard.com:8443/standard/tradeQuery
//关闭https://t-wapi.bhecard.com:8443/standard/close
//分账+退货环境请求地址https://t-wapi.bhecard.com:6111+[urlmethod]
/**
* 构造函数
* @date 2021-01-25
*/
public function __construct(array $data = [])
{
$this->config = $data;
}
/**
* 设置baseUrl
* @date 2022-06-06
*/
public function setUrl($url)
{
$this->url = $url;
}
/**
* 生成提交结果参数
* @param array $data 公共参数 一般包含method参数
* @param array $bizContent 业务参数
* @return bool|string
*/
public function actionApi($data, $url = '')
{
try {
$post_url = $this->url . $url;
$result = http_data_post($post_url, $data);
return $result;
} catch (\Exception $e) {
$result = [
'message' => $e->getMessage()
];
return $result;
}
}
//*********************************************** 生成签名和验签 ***********************************************
/**
* 生成签名
* @param array $data 需要签名的数据
* @date 2022-06-08
*/
public function getSign($data)
{
//先进行键升序排列
ksort($data);
//以&连接,拼接成key=value&key=value的字符串
$str = arrayToUrlParams($data);
//签名
$sign = getSignData($str, $this->config['private_key'], 1);
return $sign;
}
/**
* 验签SHA256WithRSA
* @param array $data 需要验证的数据
* @param string $sign 签名
* @date 2022-06-08
*/
public function verifySign($data, $sign)
{
//先进行键升序排列
ksort($data);
//以&连接,拼接成key=value&key=value的字符串
$str = arrayToUrlParams($data);
//验证签名
$result = verifySignData($str, $sign, $this->config['public_key'], 2);
return $result;
}
//*********************************************** 敏感信息加密和解密 ***********************************************
/**
* 生成对称秘钥 md5加密为32位
* @date 2022-06-07
*/
public function getKey()
{
return md5($this->key);
}
/**
* AES-265-ECB加密
* @param array $arr 加密信息
* @param string $key 加密秘钥
* @date 2022-06-08
*/
public function encrypt($arr, $key)
{
//转json
$arr = json_encode($arr);
//返回加密结果
return encryptData($arr, $key, 'aes-256-ecb');
}
/**
* 生成数字信封
* @param string $data 需要加密的信息
* @date 2022-06-08
*/
public function encryptWithPKCS1($data)
{
$encrypted = encryptDataByReceiveCert($data, $this->config['public_key'], 2);
return $encrypted;
}
}