Ai
1 Star 0 Fork 0

中通技术团队/zopsdk-php

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ZopClient.php 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
天羽ちよこ 提交于 2019-04-03 14:54 +08:00 . 支持直接设置请求json
<?php
namespace zop;
include "ZopHttpUtil.php";
class ZopClient
{
private $zopProperties;
private $httpClient;
/**
* ZopClient constructor.
* @param $zopProperties
*/
public function __construct($zopProperties)
{
$this->zopProperties = $zopProperties;
$this->httpClient = new ZopHttpUtil();
}
public function execute($zopRequest)
{
$url = $zopRequest-> getUrl();
$params = $zopRequest-> getParams();
$fixedParams = Array();
foreach ($params as $k => $v) {
if (gettype($v) != "string") {
$fixedParams += [$k => json_encode($v)];
} else {
$fixedParams += [$k => $v];
}
}
$str_to_digest = "";
foreach ($fixedParams as $k => $v) {
$str_to_digest = $str_to_digest.$k."=".$v."&";
}
$str_to_digest = substr($str_to_digest, 0, -1).$this->zopProperties->getKey();
$data_digest = base64_encode(md5($str_to_digest, TRUE));
$headers = Array(
"Content-Type: application/x-www-form-urlencoded; charset=UTF-8",
"x-companyid: ".$this->zopProperties->getCompanyid(),
"x-datadigest: ".$data_digest
);
return $this->httpClient->post($url, $headers, http_build_query($fixedParams), 2000);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/zto_express/zopsdk-php.git
git@gitee.com:zto_express/zopsdk-php.git
zto_express
zopsdk-php
zopsdk-php
master

搜索帮助