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.
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 fubei ;
class Base
{
protected $config ; //付呗配置
protected $gateway = 'https://shq-api.51fubei.com/gateway/agent' ; //请求网关
/**
* 构造函数
* @date 2021-01-25
*/
public function __construct ( array $data = [])
{
$this -> config = $data ;
}
/**
* 生成提交结果参数
* @param array $commonData 公共参数 一般包含method参数
* @param array $bizContent 业务参数
* @return bool|string
*/
public function actionApi ( $commonData , $bizContent = [])
{
$commonData [ 'app_id' ] = $this -> config [ 'app_id' ]; //商户开放平台id( 商户后台生成) 商户级接入该字段必填, 与vendor_sn二选一, 根据接口级别进行判定
$commonData [ 'nonce' ] = createNonceStr ( 32 ); //请求端随机生成数
$commonData [ 'biz_content' ] = json_encode ( $bizContent ); //请求参数的集合,除公共参数外所有请求参数都必须放在这个参数中
$commonData [ 'sign' ] = $this -> getSign ( $commonData ); //签名
try {
$result = http_data_post ( $this -> gateway , $commonData );
// 记录日志
$uid = defined ( 'UID' ) ? UID : '' ;
platformLog ( $commonData , $result , 'fubei_request_uid_' . $uid );
return $result ;
} catch ( \Exception $e ) {
throw new \Exception ( '交易异常' . $e -> getMessage ());
}
}
/**
* 生成签名
* @param $data
* @return string
*/
public function getSign ( $data )
{
// 数组键名小写
$arr = array_change_key_case ( $data );
// 先进行键升序排列
ksort ( $arr );
// 以&连接,拼接成key=value&key=value的字符串
$str = arrayToUrlParams ( $arr );
// 拼接秘钥
$str .= $this -> config [ 'app_secret' ];
//获取待加密字符串
return strtoupper ( md5 ( $str ));
}
}