bztang-admin/app/outside/services/OutsideAppService.php

77 lines
1.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Created by PhpStorm.
*
*
*
* Date: 2022/1/6
* Time: 11:36
*/
namespace app\outside\services;
class OutsideAppService
{
/**
* 年月日 + 三位公众号 + 5位随机数
* @return string
*/
public static function createAppId()
{
$currentUniacid = \YunShop::app()->uniacid;
$unique = hexdec(uniqid());
$random = substr($unique, -5, 5);
$uniacid = str_pad($currentUniacid,3,0,STR_PAD_LEFT);
$appId = date("Ymd"). $uniacid.$random;
return $appId;
}
public static function createSecret($appId = '')
{
if (empty($appId)) {
$appId = self::createAppId();
}
return strtoupper(md5($appId.str_random()));
}
public function jiamihash($data, $appSecret, $isBinary = false)
{
$sign = hash_hmac('sha256', $data, $appSecret,$isBinary);
return $sign;
}
/**
* 将参数转换成k=v拼接的形式
* @param $parameter
* @return string
*/
public function toQueryString($parameter)
{
//按key的字典序升序排序并保留key值
ksort($parameter);
$strQuery="";
foreach ($parameter as $k=>$v){
//不参与签名、验签
if($k == "sign"){
continue;
}
if($v === null) {$v = '';}
$strQuery .= strlen($strQuery) == 0 ? "" : "&";
$strQuery.=$k."=".$v;
}
return $strQuery;
}
}