Browse Source

水务接口对接 删除一些扩展 删除测试方法

master
wanghongjun 1 year ago
parent
commit
440e318949
  1. 10
      .env
  2. 34
      app/controller/admin/Login.php
  3. 19
      app/controller/api/Test.php
  4. 2
      app/controller/wechat/Base.php
  5. 11
      app/controller/wechat/Wechat.php
  6. 272
      app/service/webService/FeeService.php
  7. 4
      composer.json
  8. 1
      route/apiRoute.php

10
.env

@ -20,4 +20,12 @@ default_lang = zh-cn
TOKEN = invoiceApi
APPID = wx95f03b3c0c33335f
APPSECRET = 117f446ea2bfdd7ef28e131faafd248b
REDIRECT_URI = https://intp.xingtongworld.com/admin/Login/wx
REDIRECT_URI = https://intp.xingtongworld.com/wechat/Login/wx
[WSDL]
SOAP_URL = http://120.234.15.170:4000/FeeService.dll/soap/IFeeService
SOAP_PORT = 4000
[SMS]
USERNAME = clygysw
PASSWORD = r9jndi

34
app/controller/admin/Login.php

@ -78,40 +78,6 @@ class Login extends Base {
return $this->buildSuccess($userInfo->toArray(), '登录成功');
}
/**
* 测试 xml接口请求
* @return Response
* @throws \SoapFault
*/
public function test(): Response {
$wsdl = 'http://192.168.66.182:8080/webservice/test?wsdl';
// 创建一个SoapClient实例
$client = new \SoapClient($wsdl);
// 假设WebService提供了一个名为"getData"的方法
// 你需要传递必要的参数调用这个方法
$parameters = array(
'pucode' => 'value1',
'param2' => 'value2'
);
// 调用WebService的方法
try {
$result = $client->__call("test", $parameters);
// 打印结果
print_r($result);
} catch (SoapFault $e) {
// 错误处理
echo "Error: ", $e->getMessage();
}
die;
return $this->buildSuccess([], '登录成功');
}
/**
* 获取用户信息
* @return Response

19
app/controller/api/Test.php

@ -0,0 +1,19 @@
<?php
declare (strict_types=1);
namespace app\controller\api;
use app\service\webService\FeeService;
use NuSoap\Client\Client;
class Test extends Base
{
public function index()
{
$FeeService = new FeeService('41107394');
dump($FeeService->getUserTotal());
die;
}
}

2
app/controller/wechat/Base.php

@ -67,7 +67,7 @@ class Base extends BaseController {
"aud" => '', //面象的用户,可以为空
"iat" => time(), //签发时间
"nbf" => time() + 3, //在什么时候jwt开始生效 (这里表示生成100秒后才生效)
"exp" => 0,//time() + 7200, //token 过期时间
"exp" => time() + 7200, //token 过期时间
"data" => $data //记录的userid的信息,这里是自已添加上去的,如果有其它信息,可以再添加数组的键值对
);
return JWT::encode($token, $key, "HS384"); //根据参数生成了token,可选:HS256、HS384、HS512、RS256、ES256等

11
app/controller/wechat/Wechat.php

@ -5,6 +5,7 @@ namespace app\controller\wechat;
use app\model\WechatPucode;
use app\model\WechatUser;
use app\service\webService\FeeService;
use app\validate\WechatUser as WechatUserValidate;
use app\service\wechat\WechatService;
use app\util\ReturnCode;
@ -65,6 +66,16 @@ class Wechat extends Base
$mobile = $param['mobile'];
$pucode = $param['pucode'];
$FeeService = new FeeService($pucode);
$feeUserInfo = $FeeService->getUsers();
if ($feeUserInfo['MsgID'] != $pucode) {
throw new \Exception('用户不存在');
}
if ($feeUserInfo['CellPhone'] != $mobile) {
throw new \Exception('手机号或用户编号错误');
}
$wechat_user_id = $request->wechat_user_id;
$userData = ['phone' => $mobile];

272
app/service/webService/FeeService.php

@ -0,0 +1,272 @@
<?php
namespace app\service\webService;
use fast\FuncException;
class FeeService
{
protected $wsdl;
protected $port;
protected $pucode;
const ONE_KEY = 'SOAP-ENV:Body';
public function __construct($pucode)
{
$this->wsdl = env('wsdl.soap_url');
$this->port = env('wsdl.soap_port');
$this->pucode = $pucode;
}
/**
* 查询用户数量
* @return mixed
* @throws FuncException
*/
public function getUserTotal()
{
$arr = ['pucode' => $this->pucode];
$method = 'GetUserTotal';
$res = $this->curl($method, $this->xml_str($arr));
$key = 'NS1:' . $method . 'Response';
$this->dataValidate($res, $key);
return $res[$key];
}
/**
* 查询用户基本信息
* @return mixed
* @throws FuncException
*/
public function getUsers(): array
{
$arr = ['pucode' => $this->pucode];
$method = 'GetUsers';
$res = $this->curl($method, $this->xml_str($arr));
$key = 'NS1:GetUsersResponse';
$this->dataValidate($res, $key);
$key2 = 'NS2:TUserInfo';
$this->dataValidate($res[$key], $key2, 2);
return $res[$key][$key2];
}
/**
* 查询用户表资料
* @return mixed
* @throws FuncException
*/
public function getWaterMeters()
{
$arr = ['userCode' => $this->pucode];
$method = 'GetWaterMeters';
$res = $this->curl($method, $this->xml_str($arr));
$key = 'NS1:GetWaterMetersResponse';
$this->dataValidate($res, $key);
$key2 = 'NS2:TWaterMeter';
$this->dataValidate($res[$key], $key2, 2);
return $res[$key][$key2];
}
/**
* 查询用户抄表信息
* @param $param ['startCostYearMonth' => '2024-01','endCostYearMonth' => '2024-02']
* @throws FuncException
*/
public function getReadingDetail(array $param = [])
{
$arr = ['userCode' => $this->pucode];
if ($param) {
$arr = array_merge($arr, $param);
}
$method = 'GetReadingDetail';
$res = $this->curl($method, $this->xml_str($arr));
$key = 'NS1:GetReadingDetailResponse';
$this->dataValidate($res, $key);
$key2 = 'NS2:TUserReading';
$this->dataValidate($res[$key], $key2, 2);
return $res[$key][$key2];
}
/**
* 查询用户费用信息
* @param $param ['startCostYearMonth' => '2024-01','endCostYearMonth' => '2024-02','PaymentStatus' => '0']
* PaymentStatus 0:所有 1:未缴 2:已缴 5:部分缴
* @throws FuncException
*/
public function getComputeDetail(array $param = [])
{
$arr = ['userCode' => $this->pucode];
if ($param) {
$arr = array_merge($arr, $param);
}
$method = 'GetComputeDetail';
$res = $this->curl($method, $this->xml_str($arr));
$key = 'NS1:GetComputeDetailResponse';
$this->dataValidate($res, $key);
$key2 = 'NS2:TComputeDetail';
$this->dataValidate($res[$key], $key2, 2);
return $res[$key][$key2];
}
protected function xml_str($arr): string
{
$xml_arr = [];
foreach ($arr as $key => $value) {
$xml_arr[] = "<{$key}>" . $value . "</{$key}>";
}
return implode("\r\n", $xml_arr);
}
/**
* POST 调用xml接口
* @param $method
* @param $xml_filed
* @return array
* @throws FuncException
*/
protected function curl($method, $xml_filed): array
{
$xml = <<<XML
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http:schemas.xmlsoap.org/soap/encoding/">
<NS1:{$method} xmlns:NS1="urn:FeeServiceIntf-IFeeService">
{$xml_filed}
</NS1:{$method}>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
XML;
$wsdl = 'http://120.234.15.170:4000/FeeService.dll/soap/IFeeService';
// 初始化cURL会话
$ch = curl_init();
// 设置cURL选项
curl_setopt($ch, CURLOPT_URL, $wsdl); // 目标URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 返回结果而不是输出
curl_setopt($ch, CURLOPT_POST, true); // 发送POST请求
// 设置POST字段
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); // 设置HTTP头
// 执行cURL会话
$response = curl_exec($ch);
// 检查是否有错误发生
if (curl_errno($ch)) {
throw new FuncException('cURL error: ' . curl_error($ch));
}
// 关闭cURL会话
curl_close($ch);
$array = $this->getXmlDom($response);
return $this->curlValidate($array);
}
/**
*
* @param $response
* @return array
*/
protected function getXmlDom($response): array
{
$dom = new \DOMDocument();
$dom->loadXML($response);
return $this->xmlToArray($dom->documentElement);
}
/**
*
* @param $node
* @return array|mixed
*/
protected function xmlToArray($node)
{
$output = [];
if ($node->hasChildNodes()) {
foreach ($node->childNodes as $child) {
if ($child->nodeType === XML_ELEMENT_NODE) {
$output[$child->nodeName] = $this->xmlToArray($child);
} elseif ($child->nodeType === XML_TEXT_NODE) {
$output = $child->nodeValue;
}
}
}
return $output;
}
/**
*
* @param $array
* @return mixed
* @throws FuncException
*/
protected function curlValidate($array)
{
if (!isset($array[self::ONE_KEY])) {
throw new FuncException('数据获取失败 -0');
}
return $array[self::ONE_KEY];
}
/**
*
* @param $data
* @param $key
* @param int $level
* @throws FuncException
*/
public function dataValidate($data, $key, int $level = 1)
{
if (!isset($data[$key])) {
throw new FuncException("数据获取失败 -{$level}");
}
}
}

4
composer.json

@ -21,7 +21,9 @@
"topthink/framework": "^6.0",
"topthink/think-orm": "^2.0",
"topthink/think-migration": "^3.0",
"firebase/php-jwt": "^6.4"
"firebase/php-jwt": "^6.4",
"ext-dom": "*",
"ext-curl": "*"
},
"require-dev": {
"symfony/var-dumper": "^4.2",

1
route/apiRoute.php

@ -9,6 +9,7 @@ Route::group('api', function() {
// 微信验证路由地址
Route::rule('InvoiceIssuance/add', 'api.InvoiceIssuance/add', 'post')->middleware(\app\middleware\WechatAuth::class);
Route::rule('InvoiceIssuance/delete', 'api.InvoiceIssuance/delete', 'post')->middleware(\app\middleware\WechatAuth::class);
Route::rule('Test/index', 'api.Test/index', 'get');
//MISS路由定义
//Route::miss('api.Miss/index');
});//->middleware(app\middleware\ApiResponse::class)

Loading…
Cancel
Save