PHP

【PHP】获取程序Api地址 - 管家婆基础对接 PHP版本

小破孩
2025-04-23 / 0 评论 / 15 阅读 / 正在检测是否收录...
<?php


namespace app\common\lib\gjp;



class Apiurl
{
    protected $userId;

    protected $appKey;

    protected $SercretKey;

    protected $currentTimestamp;

    protected $dbName;

    public function __construct($userId = '********') 
    {
        $this->appKey = "*****************";

        $this->SercretKey = "*******************";

        $this->currentTimestamp = time();

        $this->userId = $userId;

        $this->dbName = '*****';
    }

    public function getApiUrl()
    {
        $url = "http://api.cmgrasp.com/CMGraspApi/GateWay";

        $instanceGjpBasic = new \app\common\lib\gjp\Basic();

        $instanceStr = new \app\common\lib\data\Str();

        $randamStr = $instanceStr->setNonce(32,true);

        $md5BeforeStr = "AppKey".$this->appKey."InvalidTime".date('YmdHis',$this->currentTimestamp)."RandamStr".$randamStr."UserId".$this->userId.$this->SercretKey;

        $data = [
            'MethodName'  => (string)"graspcm.cmapi.getcustomerapiurl",
            'AppKey'      => (string)$this->appKey,
            'UserId'      => (string)$this->userId,
            'InvalidTime' => (string)date('Y-m-d H:i:s'),
            'RandamStr'   => (string)$randamStr,
            'SignStr'     => (string)md5($md5BeforeStr),
            'DbName'      => (string)$this->dbName
        ];

        $jsonData = json_encode($data);

        $result = $instanceGjpBasic->curlRequest($url,"POST",$jsonData,true,false);

        if($result['RetCode'] != 0){
            $this->getApiUrl();
        }

        $resultData = json_decode($result['RetMsg'],true);

        return $resultData;
    }
}
0

评论 (0)

取消