Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
third-api
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
朱招明
third-api
Commits
5e32b215
Commit
5e32b215
authored
Oct 14, 2023
by
朱招明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
67c32cd0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
25 deletions
+94
-25
README.md
README.md
+28
-0
Base.php
src/WeiKe/Base.php
+43
-0
Power.php
src/WeiKe/Rest/Power.php
+23
-25
No files found.
README.md
View file @
5e32b215
第三方API包
===
## laravel 配置文件发布
`php artisan vendor:publish --tag=third-api`
## 微客API示例
~~~
#非laravel项目
$config = [
'app_key' => '',
'app_secret' => '',
];
$Power = new \SMG\ThirdApi\WeiKe\Rest\Power($config);
#laravel项目(需要发布配置文件后配置)
$Power = new \SMG\ThirdApi\WeiKe\Rest\Power();
$params = [];
#电费充值
$Power->pushOrder($params);
#电费订单查询
$Power->query($params);
#xxx
~~~
src/WeiKe/Base.php
View file @
5e32b215
...
...
@@ -8,6 +8,7 @@
namespace
SMG\ThirdApi\WeiKe
;
use
GuzzleHttp\Client
;
use
SMG\ThirdApi\WeiKe\Rest\Power
;
class
Base
...
...
@@ -31,6 +32,48 @@ class Base
}
/**
* 发送请求
* @desc
*
* @param $path
* @param $params
*
* @return mixed
* @throws \GuzzleHttp\Exception\GuzzleException
* @author [ZZM]
* @since 2023/10/14
* @modify
*/
protected
function
sendRequest
(
$path
,
$params
){
$url
=
$this
->
base_uri
.
$path
;
$client
=
new
Client
();
$common_params
=
[
'app_key'
=>
$this
->
config
[
'app_key'
],
'timestamp'
=>
time
(),
'client'
=>
getClientIP
(),
'v'
=>
'1.0'
,
'format'
=>
'json'
,
];
$common_params
[
'sign'
]
=
$this
->
getSign
(
array_merge
(
$common_params
,
$params
));
$url
=
$url
.
'?'
.
http_build_query
(
$common_params
);
$response
=
$client
->
post
(
$url
,
[
'headers'
=>
[
'Content-Type'
=>
'application/x-www-form-urlencoded'
,
],
'form_params'
=>
$params
,
]);
if
(
$response
->
getStatusCode
()
===
200
)
{
$body
=
$response
->
getBody
()
->
getContents
();
return
json_decode
(
$body
);
}
else
{
throw
new
\Exception
(
"请求失败,状态码:
{
$response
->
getStatusCode
()
}
"
);
}
}
/**
* 签名
* @desc
*
...
...
src/WeiKe/Rest/Power.php
View file @
5e32b215
...
...
@@ -13,6 +13,11 @@ use SMG\ThirdApi\WeiKe\Base;
class
Power
extends
Base
{
const
PATH
=
[
'pushOrder'
=>
'rest/Power/pushOrder'
,
'query'
=>
'rest/Power/query'
,
];
/**
* 电费充值
* @desc
...
...
@@ -27,31 +32,23 @@ class Power extends Base
*/
public
function
pushOrder
(
$params
)
{
$url
=
$this
->
base_uri
.
'rest/Power/pushOrder'
;
$client
=
new
Client
();
$common_params
=
[
'app_key'
=>
$this
->
config
[
'app_key'
],
'timestamp'
=>
time
(),
'client'
=>
getClientIP
(),
'v'
=>
'1.0'
,
'format'
=>
'json'
,
];
$common_params
[
'sign'
]
=
$this
->
getSign
(
array_merge
(
$common_params
,
$params
));
$url
=
$url
.
'?'
.
http_build_query
(
$common_params
);
$response
=
$client
->
post
(
$url
,
[
'headers'
=>
[
'Content-Type'
=>
'application/x-www-form-urlencoded'
,
],
'form_params'
=>
$params
,
]);
if
(
$response
->
getStatusCode
()
===
200
)
{
$body
=
$response
->
getBody
()
->
getContents
();
return
json_decode
(
$body
);
}
else
{
throw
new
\Exception
(
"请求失败,状态码:
{
$response
->
getStatusCode
()
}
"
);
return
$this
->
sendRequest
(
self
::
PATH
[
'pushOrder'
],
$params
);
}
/**
* 电费订单查询
* @desc
*
* @param $params
*
* @return mixed
* @throws \Exception
* @since 2023/10/14
* @modify
* @author [ZZM]
*/
public
function
query
(
$params
)
{
return
$this
->
sendRequest
(
self
::
PATH
[
'query'
],
$params
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment