Skip to content

Commit

Permalink
新增 使用json-rpc方式进行post提交
Browse files Browse the repository at this point in the history
luguohuakai committed Apr 2, 2024
1 parent faf752b commit 1c6235f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Func.php
Original file line number Diff line number Diff line change
@@ -198,7 +198,7 @@ public static function joinParams($path, $params)
* 'Content-Type: application/json; charset=utf-8', <br>
* 'Content-Length: 48', <br>
* ] <br>
* @param int $type 0:默认数组 1:模拟表单提交 2:模拟json提交
* @param int $type 0:默认数组 1:模拟表单提交 2:模拟json提交 3:json-rpc方式提交
* @return mixed
*/
public static function post($url, $post_data, array $header = [], int $type = 0)
@@ -215,7 +215,7 @@ public static function post($url, $post_data, array $header = [], int $type = 0)
* 'Content-Type: application/json; charset=utf-8', <br>
* 'Content-Length: 48', <br>
* ] <br>
* @param int $type 0:默认数组 1:模拟表单提交 2:模拟json提交
* @param int $type 0:默认数组 1:模拟表单提交 2:模拟json提交 3:json-rpc方式提交
* @return mixed
*/
public static function delete($url, array $data = [], array $header = [], int $type = 0)
@@ -232,7 +232,7 @@ public static function delete($url, array $data = [], array $header = [], int $t
* 'Content-Type: application/json; charset=utf-8', <br>
* 'Content-Length: 48', <br>
* ] <br>
* @param int $type 0:默认数组 1:模拟表单提交 2:模拟json提交
* @param int $type 0:默认数组 1:模拟表单提交 2:模拟json提交 3:json-rpc方式提交
* @return mixed
*/
public static function put($url, array $data = [], array $header = [], int $type = 0)
@@ -260,8 +260,12 @@ private static function request($method, $url, $data = [], $header = [], $type =
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
} elseif ($type === 2) {
// json方式提交
$json_data = json_encode($data, JSON_UNESCAPED_UNICODE);
$header = array_merge($header, ['Content-Type: application/json; charset=utf-8']);
$json_data = json_encode($data, JSON_UNESCAPED_UNICODE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
} elseif ($type === 3) {
$header = array_merge($header, ['Content-Type: application/json-rpc']);
$json_data = json_encode($data, JSON_UNESCAPED_UNICODE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
} else {
if (!empty($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

0 comments on commit 1c6235f

Please sign in to comment.