Browse Source

update

master
DengBiao 1 year ago
parent
commit
078f5033c8
7 changed files with 350 additions and 270 deletions
  1. +57
    -41
      src/applet/app/controllers/AliCallBackController.php
  2. +54
    -0
      src/applet/app/controllers/Alipay/BPassController.php
  3. +6
    -0
      src/common/Model/SelfSupportForSchoolInfo.php
  4. +0
    -87
      src/common/Service/AliBPass/AliEcoService.php
  5. +0
    -112
      src/common/Service/AliBPass/AliEcoServiceBack.php
  6. +231
    -28
      src/common/Service/AliBPass/demo/AliEcoService.php
  7. +2
    -2
      src/common/Service/AliBPass/demo/EcoApiClient.php

+ 57
- 41
src/applet/app/controllers/AliCallBackController.php View File

@@ -4,6 +4,7 @@ namespace SRVX\Api\Controllers;

use SRVX\Model\SelfSupportForSchoolInfo;
use SRVX\Model\SelfSupportForSchoolOrd;
use SRVX\Model\SelfSupportForUserFaceInfo;
use SRVX\Model\UserIdentity;
use SRVX\Traits\BasisFun;

@@ -87,49 +88,64 @@ class AliCallBackController extends \Phalcon\Mvc\Controller
//获取用户身份信息
$userIdentityId = 0;
if (isset($biz_content["buyer_info"])) {
$userIdentityId = $biz_content["buyer_info"]["roster_code"] ?? 0; //身份id
$userIdentityId = $biz_content["buyer_info"]["roster_code"] ?? 0; //身份id
}
$selfSupportForSchoolInfo = UserIdentity::findFirst("id = '{$userIdentityId}'");
if (empty($selfSupportForSchoolInfo)) {
$response = [
"code" => "40000",
"msg" => "Business Failed",
"sub_code" => "20000",
"sub_msg" => "not found user identity",
];
} else {
//新增`自营-学校-订单表`数据
$model = new SelfSupportForSchoolOrd();
$model->enterprise_id = $selfSupportForSchoolInfo->enterprise_id;
$model->uid = $selfSupportForSchoolInfo->uid;
$model->user_identity_id = $userIdentityId;
$model->out_order_no = $biz_content["out_order_no"] ?? "";
$model->trade_no = $biz_content["trade_no"] ?? "";
$model->consumer = $biz_content["consumer"] ?? "";
$model->buyer_id = $biz_content["buyer_id"] ?? "";
$model->seller_id = $biz_content["seller_id"] ?? "";
$model->device_sn = $biz_content["device_sn"] ?? "";
$model->school_name = $biz_content["buyer_info"]["school_name"] ?? "";
$model->school_code = $biz_content["buyer_info"]["school_code"] ?? "";
$model->store_business_scenario = $biz_content["store_business_scenario"] ?? "";
$model->store_name = $biz_content["store_name"] ?? "";
$model->cp_store_id = $biz_content["cp_store_id"] ?? "";
$model->merchant_name = $biz_content["merchant_name"] ?? "";
$model->cp_merchant_id = $biz_content["cp_merchant_id"] ?? "";
$model->trade_amount = $biz_content["trade_amount"] ?? "";
$model->face_time = $biz_content["face_time"] ?? "";
$model->order_status = ($biz_content["order_status"] == "ORDER_SUCCESS") ? 2 : 1; //支付状态
$model->debt_business_code = $biz_content["debt_business_code"] ?? "";
$model->debt_business_msg = $biz_content["debt_business_msg"] ?? "";
$model->create_at = date("Y-m-d H:i:s");
$model->update_at = date("Y-m-d H:i:s");
$model->save();

$response = [
"code" => "10000",
"msg" => "Success",
];
$userIdentity = UserIdentity::findFirst("id = '{$userIdentityId}'");
if (empty($userIdentity)) {
$selfSupportForSchoolInfo = SelfSupportForUserFaceInfo::findFirst("user_id = '{$biz_content["buyer_id"]}'");
if (!$selfSupportForSchoolInfo) {
$userIdentity = UserIdentity::findFirst("id = '{$selfSupportForSchoolInfo->user_identity_id}'");
if (empty($userIdentity)) {
$response = [
"code" => "40000",
"msg" => "Business Failed",
"sub_code" => "20000",
"sub_msg" => "not found user identity",
];
break;
}
} else {
$response = [
"code" => "40000",
"msg" => "Business Failed",
"sub_code" => "20000",
"sub_msg" => "not found user identity",
];
break;
}
}

//新增`自营-学校-订单表`数据
$model = new SelfSupportForSchoolOrd();
$model->enterprise_id = $userIdentity->enterprise_id;
$model->uid = $userIdentity->uid;
$model->user_identity_id = $userIdentityId;
$model->out_order_no = $biz_content["out_order_no"] ?? "";
$model->trade_no = $biz_content["trade_no"] ?? "";
$model->consumer = $biz_content["consumer"] ?? "";
$model->buyer_id = $biz_content["buyer_id"] ?? "";
$model->seller_id = $biz_content["seller_id"] ?? "";
$model->device_sn = $biz_content["device_sn"] ?? "";
$model->school_name = $biz_content["buyer_info"]["school_name"] ?? "";
$model->school_code = $biz_content["buyer_info"]["school_code"] ?? "";
$model->store_business_scenario = $biz_content["store_business_scenario"] ?? "";
$model->store_name = $biz_content["store_name"] ?? "";
$model->cp_store_id = $biz_content["cp_store_id"] ?? "";
$model->merchant_name = $biz_content["merchant_name"] ?? "";
$model->cp_merchant_id = $biz_content["cp_merchant_id"] ?? "";
$model->trade_amount = $biz_content["trade_amount"] ?? "";
$model->face_time = $biz_content["face_time"] ?? "";
$model->order_status = ($biz_content["order_status"] == "ORDER_SUCCESS") ? 2 : 1; //支付状态
$model->debt_business_code = $biz_content["debt_business_code"] ?? "";
$model->debt_business_msg = $biz_content["debt_business_msg"] ?? "";
$model->create_at = date("Y-m-d H:i:s");
$model->update_at = date("Y-m-d H:i:s");
$model->save();

$response = [
"code" => "10000",
"msg" => "Success",
];
break;
default:
$response = [


+ 54
- 0
src/applet/app/controllers/Alipay/BPassController.php View File

@@ -36,4 +36,58 @@ class BPassController extends ControllerBase
}
}

public function AlipayPlanetEcocampusApiDebtPageQueryDebtInfoAction()
{
if ($this->request->isPost()) {
$args = $this->request->getJsonRawBody(true);

$result = (new AliEcoService())->alipayPlanetEcocampusApiDebtPageQueryDebtInfo(
$args["face_uid"],$args["school_code"], $args["page_no"], $args["page_size"]
);

if (!$result["status"]) {
$this->api(Msg::NewError($result["data"]["code"] ?? 500, $result["msg"]));
}
$this->api($result["data"]);
} else {
$this->api(Msg::NewError(500, '提交方式错误!'));
}
}

public function AlipayPlanetEcocampusApiDebtRepayAction()
{
if ($this->request->isPost()) {
$args = $this->request->getJsonRawBody(true);

$result = (new AliEcoService())->alipayPlanetEcocampusApiDebtRepay(
$args["out_order_no"],$args["merchant_code"]
);

if (!$result["status"]) {
$this->api(Msg::NewError($result["data"]["code"] ?? 500, $result["msg"]));
}
$this->api($result["data"]);
} else {
$this->api(Msg::NewError(500, '提交方式错误!'));
}
}

public function AlipayPlanetEcocampusApiDebtCancelAction()
{
if ($this->request->isPost()) {
$args = $this->request->getJsonRawBody(true);

$result = (new AliEcoService())->alipayPlanetEcocampusApiDebtRepay(
$args["out_order_no"],$args["merchant_code"]
);

if (!$result["status"]) {
$this->api(Msg::NewError($result["data"]["code"] ?? 500, $result["msg"]));
}
$this->api($result["data"]);
} else {
$this->api(Msg::NewError(500, '提交方式错误!'));
}
}

}

+ 6
- 0
src/common/Model/SelfSupportForSchoolInfo.php View File

@@ -18,6 +18,12 @@ class SelfSupportForSchoolInfo extends BasicModel
*/
public $enterprise_id;

/**
*
* @var int
*/
public $user_identity_id;

/**
*
* @var string


+ 0
- 87
src/common/Service/AliBPass/AliEcoService.php View File

@@ -1,87 +0,0 @@
<?php

namespace SRVX\Service\AliBPass;

use SRVX\Service\BaseService;
use EcoAopClient;


class AliEcoService extends BaseService
{
public $serverUrl = "https://cloudpaygw.alipay-eco.com";
public $appId = '20230803121700004722802100016020';
public $privateKey = 'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCSGJ9ob4kmGy6y4YeynjKJc/LSg02EXjLErPZSfVrAOy69FTRfBDbazlxpfl6YCAxDdT5ZcspB5kS2XYOY4dmqqPmF4VywmcjmZM8IxZFl1p7YC8BOlP6JrzDPwVl3hn4z3Em1byj8ANLY/AxAaW9W43FSIX+cSfdJThTlxGcbHZFM3kqu++hgFc/E+ar1nB0garqh03ESjatO4b6tuHM57ou7M+fXsoIf3gaL1IDZpeAoRh5sLCBLIbLz55tF0DcOaFsK7NUImnabJDRtrM1IN0lDZkQYAzL+JFsAq+ncRJm60Vd1jq/pXML/cFVHQQgdnjUd2u2NJTSMiCKCftmdAgMBAAECggEARzt+LduEEXJbeJiCI1MC7QX9tSqUFyAevMpgZ6P7JZM1nLfECzfwzwqjAES/Nn1mDVYTCmXvu+XcRtadnWMxUAaHcwGIwgqZa8xnLa220OKuHETOhQIcgWFL+WAakS6gRgT4Y2BJqWV1aJqsFpPR15mZ3SO8JqXhznol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ublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuWFuSpwY/2llLhy5Hxkqcc0qQFQOvemkYOI4S43L4qArX4x+DQN1RFuvfGuwOLScBKaoDYHsu9PSoTtcIj4obhhexbWHfelcsouV7Pj4YChrOkOLHAMLDQhGRXaZyXQAJdk2DoBkJ0vBDD/b1gZT8QznPopvuT4Y0rx/a2vK+5B/XV0wUuP2PnpWoPxNSwr7neFWvUdkC7yJJg4zJ1INLYy9TgHH3LKYrsEDbQzPJyMPFhD0zDb36b62q3tQYc1w8JknS6XeXMkX1Tu4zZbAxyIiv3J1FK8y7dtoRi9gLgo0uLsXWDn5AwAlzqfOERgLMWD2r6FE8tOXVbMha6IImQIDAQAB'; //平台公钥
public $aesKey = 'HOrPS0V4BthAPfgSdbHWwy0TwPnC8TQAQZIOjc8vOzI='; //加密密钥

public function __construct()
{
// if ((APP_ENV == 'dev')) {
// $this->serverUrl = 'https://dev-cloudpaygw.alipay-eco.com';
// }
}

/**
* alipay.planet.ecocampus.api.roster.signUpInfo(签约信息同步)
* @param $face_uid string 学生刷脸编号(不可修改)
* @param $parent_uid string 家长uid(可修改) 2088122417040252
* @param $parent_logon_id string 家长支付宝账号脱敏信息(可修改)
* @param $roster_name string 学生姓名(可修改)
* @param $out_roster_code string 外部花名册编号(不可修改)
* @param $school_code string 学校内标(不可修改)
* @param $school_name string 学校名称(不可修改)
* @param $face_open_status string 刷脸开通状态(可修改)
* @param $scan_face_pay_status string 刷脸支付开通状态(可修改)
* @return array
*/

public function alipayPlanetEcocampusApiRosterSignUpInfo($face_uid, $parent_uid, $parent_logon_id, $roster_name, $out_roster_code, $school_code, $school_name, $face_open_status = "OFF", $scan_face_pay_status = "OFF"): array
{
$privateKey = $this->privateKey;
$alipayPublicKey = $this->alipayPublicKey;
$alipayConfig = new \AlipayConfig();
$alipayConfig->setServerUrl($this->serverUrl); //行业云接口地址
$alipayConfig->setAppId($this->appId); //行业云上的服务商isv_app_id
$alipayConfig->setPrivateKey($privateKey);
$alipayConfig->setFormat("json");
$alipayConfig->setAlipayPublicKey($alipayPublicKey);
$alipayConfig->setCharset("UTF-8");
$alipayConfig->setSignType("RSA2");

$alipayClient = new EcoAopClient($alipayConfig);
//加密密钥,仅在接口内容需要加密时生效
$alipayClient->encryptKey = $this->aesKey;
$alipayClient->encryptType = "AES";

try {
$request = new \AlipayPlanetEcocampusApiRosterSignUpInfo();
$params = [
"face_uid" => $face_uid,
"face_open_status" => $face_open_status,
"parent_uid" => $parent_uid,
"parent_logon_id" => $parent_logon_id,
"roster_name" => $roster_name,
"out_roster_code" => $out_roster_code,
"school_code" => $school_code,
"school_name" => $school_name,
"scan_face_pay_status" => $scan_face_pay_status,
];
$request->setBizContent(json_encode($params));

//加密开关,仅在接口内容需要加密时生效
$request->setNeedEncrypt(true);

$response = $alipayClient->execute($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$responseData = json_decode(json_encode($response->$responseNode), true);
if ($responseData['code'] == 10000) {
return $this->returnRes(true, $responseData['msg'], $responseData);
} else {
return $this->returnRes(false, ($responseData['sub_msg'] ?? $responseData['msg']), $responseData);
}
} catch (\Exception $exception) {
return $this->returnRes(false, $exception->getMessage());
}
}

}

+ 0
- 112
src/common/Service/AliBPass/AliEcoServiceBack.php View File

@@ -1,112 +0,0 @@
<?php

namespace SRVX\Service\AliBPass;

use SRVX\Service\BaseService;
use EcoAopClient;


class AliEcoService extends BaseService
{

static private $config = [];
static private $aopClient;

// public $gatewayUrl = 'https://openapi.alipay.com/gateway.do';
public $apiVersion = '1.0';
public $signType = 'RSA2';
public $postCharset = 'UTF-8';
public $format = 'json';

public $serverUrl = 'https://cloudpaygw.alipay-eco.com';
public $appId = '20230803121700004722802100016020';
public $privateKey = 'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCSGJ9ob4kmGy6y4YeynjKJc/LSg02EXjLErPZSfVrAOy69FTRfBDbazlxpfl6YCAxD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+52gy+VlJhNjCT0RHfxlGkpb+4OA4vHkbKpvTUAHjjXnMW1ZwC5CugSAchdTXTeV1im4Yms4DqJqacwoQKBgQCocPd7An8qTDIBZMOC4oT29+TYvUO+yMkAHLmx1h4QkLCkWegB4g5QkKkAGPWp3hshAj/KA0cXthFXVUG/SGZ2K6eB+nbon1N+9cDETdM4QXzN5gE/mUlupIxqRU1ouI27YYPbJSQNTrC7OkwNzfnpe/gshEj/gr5eHHvd4UrvMQKBgD2Toow7sfpV0R9rhO8aJ9njlbH15LqUK/AotK3E7zr73Uv5j/BIKS4dVC7T56L2khEUbM/y8+Rig6CdyFf3A4i4GKfbp56Sap/Haa9OP6jfep6VW7Aa1AJxPvIPgPZ2U+EuRxrwrP1EBcL5z6Cern9c9Zzs8BPUacU+Q5e8c87W'; //企业私钥
public $alipayPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuWFuSpwY/2llLhy5Hxkqcc0qQFQOvemkYOI4S43L4qArX4x+DQN1RFuvfGuwOLScBKaoDYHsu9PSoTtcIj4obhhexbWHfelcsouV7Pj4YChrOkOLHAMLDQhGRXaZyXQAJdk2DoBkJ0vBDD/b1gZT8QznPopvuT4Y0rx/a2vK+5B/XV0wUuP2PnpWoPxNSwr7neFWvUdkC7yJJg4zJ1INLYy9TgHH3LKYrsEDbQzPJyMPFhD0zDb36b62q3tQYc1w8JknS6XeXMkX1Tu4zZbAxyIiv3J1FK8y7dtoRi9gLgo0uLsXWDn5AwAlzqfOERgLMWD2r6FE8tOXVbMha6IImQIDAQAB'; //平台公钥
public $aesKey = 'HOrPS0V4BthAPfgSdbHWwy0TwPnC8TQAQZIOjc8vOzI='; //加密密钥

public function __construct()
{
if ((APP_ENV == 'dev')) {
$this->serverUrl = 'https://dev-cloudpaygw.alipay-eco.com';
}
$this->getConfig();
$this->aopClient();
}


private function aopClient()
{
if (!self::$aopClient instanceof EcoAopClient) {
self::$aopClient = new EcoAopClient(self::$config);
self::$aopClient->appId = self::$config['ali_app_id'];
//支付宝私钥值
self::$aopClient->rsaPrivateKey = self::$config['ali_private_key'];
//支付宝公钥值
self::$aopClient->alipayrsaPublicKey = self::$config['ali_public_key'];
}
// self::$aopClient->gatewayUrl = $this->gatewayUrl;
self::$aopClient->gatewayUrl = $this->serverUrl;
// self::$aopClient->apiVersion = $this->apiVersion;
self::$aopClient->signType = $this->signType;
self::$aopClient->postCharset = $this->postCharset;
self::$aopClient->format = $this->format;
}


private function getConfig()
{
if (empty(self::$config)) {
self::$config = [
"ali_app_id" => $this->appId,
"ali_private_key" => $this->privateKey,
"ali_public_key" => $this->alipayPublicKey
];
}
}

/**
* alipay.planet.ecocampus.api.roster.signUpInfo(签约信息同步)
* @param $face_uid string 学生刷脸编号(不可修改)
* @param $parent_uid string 家长uid(可修改) 2088122417040252
* @param $parent_logon_id string 家长支付宝账号脱敏信息(可修改)
* @param $roster_name string 学生姓名(可修改)
* @param $out_roster_code string 外部花名册编号(不可修改)
* @param $school_code string 学校内标(不可修改)
* @param $school_name string 学校名称(不可修改)
* @param $face_open_status string 刷脸开通状态(可修改)
* @param $scan_face_pay_status string 刷脸支付开通状态(可修改)
* @return array
*/

public function alipayPlanetEcocampusApiRosterSignUpInfo($face_uid, $parent_uid, $parent_logon_id, $roster_name, $out_roster_code, $school_code, $school_name, $face_open_status = "OFF", $scan_face_pay_status = "OFF"): array
{
try {
$request = new \AlipayPlanetEcocampusApiRosterSignUpInfo();
$params = [
"face_uid" => $face_uid,
"face_open_status" => $parent_uid,
"parent_uid" => $parent_logon_id,
"parent_logon_id" => $roster_name,
"roster_name" => $out_roster_code,
"out_roster_code" => $school_code,
"school_code" => $school_name,
"school_name" => $face_open_status,
"scan_face_pay_status" => $scan_face_pay_status,
];

$request->setBizContent(json_encode($params));
$response = self::$aopClient->execute($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
dd($responseNode);
$responseData = json_decode(json_encode($response->$responseNode), true);
if ($responseData['code'] == 10000) {
return $this->returnRes(true, $responseData['msg'], $responseData);
} else {
return $this->returnRes(false, ($responseData['sub_msg'] ?? $responseData['msg']), $responseData);
}
} catch (\Exception $exception) {
return $this->returnRes(false, $exception->getMessage());
}
}

}

+ 231
- 28
src/common/Service/AliBPass/demo/AliEcoService.php View File

@@ -21,7 +21,6 @@ class AliEcoService extends BaseService
public $charset = 'UTF-8';



/**
* alipay.planet.ecocampus.api.roster.signUpInfo(签约信息同步)
* @param $face_uid string 学生刷脸编号(不可修改)
@@ -35,7 +34,6 @@ class AliEcoService extends BaseService
* @param $scan_face_pay_status string 刷脸支付开通状态(可修改)
* @return array
*/

public function alipayPlanetEcocampusApiRosterSignUpInfo($face_uid, $parent_uid, $parent_logon_id, $roster_name, $out_roster_code, $school_code, $school_name, $face_open_status = "OFF", $scan_face_pay_status = "OFF"): array
{

@@ -43,32 +41,103 @@ class AliEcoService extends BaseService
$client = new \EcoApiClient();

// 根据环境,选择行星OPENAPI网关地址
$client->gatewayUrl = $this->serverUrl;
$client->rsaPrivateKey = $this->privateKey;
$client->gatewayUrl = $this->serverUrl;
$client->rsaPrivateKey = $this->privateKey;
$client->alipayrsaPublicKey = $this->alipayPublicKey;
$client->signType = $this->signType;
$client->format = $this->format;
$client->signType = $this->signType;
$client->format = $this->format;

// 业务参数
$bizContent["face_uid"] = $face_uid;
$bizContent["parent_uid"] = $parent_uid;
$bizContent["parentLoginId"] = $parent_logon_id;
$bizContent["roster_name"] = $roster_name;
$bizContent["out_roster_code"] = $out_roster_code;
$bizContent["school_code"] = $school_code;
$bizContent["school_name"] = $school_name;
$bizContent["face_open_status"] = $face_open_status;
$bizContent["face_uid"] = $face_uid;
$bizContent["parent_uid"] = $parent_uid;
$bizContent["parentLoginId"] = $parent_logon_id;
$bizContent["roster_name"] = $roster_name;
$bizContent["out_roster_code"] = $out_roster_code;
$bizContent["school_code"] = $school_code;
$bizContent["school_name"] = $school_name;
$bizContent["face_open_status"] = $face_open_status;
$bizContent["scan_face_pay_status"] = $scan_face_pay_status;

// 指定需要调用的service接口
$params["service"] = "alipay.planet.ecocampus.api.roster.signUpInfo";
$params["request_id"] = "" . uuid();
$params["service"] = "alipay.planet.ecocampus.api.roster.signUpInfo";
$params["request_id"] = "" . uuid();
$params["biz_content"] = json_encode($bizContent);
$params["version"] = "1.0";

// 其他参数
$params["charset"] = $this->charset;
$params["isv_app_id"] = $this->appId;
$params["utc_timestamp"] = "" . msectime();

//获取签名
$sign = $client->generateSign($params, $this->signType);

// 调用ECOAPI
$result = $client->call($params);

$jsonStr = json_encode($result);


// 响应的签名验证 转成Array 而非 Object
$resMapData = json_decode($jsonStr, true);
$this->logger($resMapData, 'alipayPlanetEcocampusApiRosterSignUpInfo', true);

// 验签
$verifyRes = checkResponse($resMapData, $client->alipayrsaPublicKey);

if ($verifyRes) {
// echo "响应验签成功";
$responseData = $resMapData["response"];
if ($responseData['code'] == 10000) {
return $this->returnRes(true, $responseData["msg"], $responseData);
} else {
return $this->returnRes(false, ($responseData['sub_msg'] ?? $responseData['msg']), $resMapData);
}
} else {
// echo "响应验签失败";
return $this->returnRes(false, "响应验签失败", []);

}
}

/**
* alipay.planet.ecocampus.api.debt.pageQueryDebtInfo(欠费列表分页查询)
* @param $face_uid string 学生刷脸编号
* @param $school_code string 学校内标
* @param $page_no int
* @param $page_size int
* @return array
*/
public function alipayPlanetEcocampusApiDebtPageQueryDebtInfo($face_uid, $school_code, $page_no, $page_size): array
{

// cleint初始
$client = new \EcoApiClient();

// 根据环境,选择行星OPENAPI网关地址
$client->gatewayUrl = $this->serverUrl;
$client->rsaPrivateKey = $this->privateKey;
$client->alipayrsaPublicKey = $this->alipayPublicKey;
$client->signType = $this->signType;
$client->format = $this->format;

// 业务参数
$bizContent["req"] = [
"face_uid" => $face_uid,
"school_code" => $school_code,
];
$bizContent["page_no"] = $page_no;
$bizContent["page_size"] = $page_size;

// 指定需要调用的service接口
$params["service"] = "alipay.planet.ecocampus.api.debt.pageQueryDebtInfo";
$params["request_id"] = "" . uuid();
$params["biz_content"] = json_encode($bizContent);
$params["version"] = "1.0";
$params["version"] = "1.0";

// 其他参数
$params["charset"] = $this->charset;
$params["isv_app_id"] = $this->appId;
$params["charset"] = $this->charset;
$params["isv_app_id"] = $this->appId;
$params["utc_timestamp"] = "" . msectime();

//获取签名
@@ -77,25 +146,159 @@ class AliEcoService extends BaseService
// 调用ECOAPI
$result = $client->call($params);

var_dump($result);
$jsonStr = json_encode($result);


// 响应的签名验证 转成Array 而非 Object
$resMapData = json_decode($jsonStr, true);
$this->logger($resMapData, 'alipayPlanetEcocampusApiDebtPageQueryDebtInfo', true);

// 验签
$verifyRes = checkResponse($resMapData, $client->alipayrsaPublicKey);

if ($verifyRes) {
// echo "响应验签成功";
$responseData = $resMapData["response"];
if ($responseData['code'] == 10000) {
return $this->returnRes(true, $responseData["msg"], $responseData);
} else {
return $this->returnRes(false, ($responseData['sub_msg'] ?? $responseData['msg']), $resMapData);
}
} else {
// echo "响应验签失败";
return $this->returnRes(false, "响应验签失败", []);

}
}

/**
* alipay.planet.ecocampus.api.debt.repay(支付欠款)
* @param $out_order_no string 外部订单号
* @param $merchant_code string 商户编号
* @return array
*/
public function alipayPlanetEcocampusApiDebtRepay($out_order_no, $merchant_code): array
{

// cleint初始
$client = new \EcoApiClient();

// 根据环境,选择行星OPENAPI网关地址
$client->gatewayUrl = $this->serverUrl;
$client->rsaPrivateKey = $this->privateKey;
$client->alipayrsaPublicKey = $this->alipayPublicKey;
$client->signType = $this->signType;
$client->format = $this->format;

// 业务参数
$bizContent["merchant_code"] = $merchant_code;
$bizContent["out_order_no"] = $out_order_no;

// 指定需要调用的service接口
$params["service"] = "alipay.planet.ecocampus.api.debt.repay";
$params["request_id"] = "" . uuid();
$params["biz_content"] = json_encode($bizContent);
$params["version"] = "1.0";

// 其他参数
$params["charset"] = $this->charset;
$params["isv_app_id"] = $this->appId;
$params["utc_timestamp"] = "" . msectime();

//获取签名
$sign = $client->generateSign($params, $this->signType);

// 调用ECOAPI
$result = $client->call($params);

$jsonStr = json_encode($result);


// 响应的签名验证 转成Array 而非 Object
$resMapData = json_decode($jsonStr, true);
$this->logger($resMapData, 'alipayPlanetEcocampusApiDebtRepay', true);

// 验签
$verifyRes = checkResponse($resMapData, $client->alipayrsaPublicKey);

if ($verifyRes) {
echo "响应验签成功";
// echo "响应验签成功";
$responseData = $resMapData["response"];
if ($responseData['code'] == 10000) {
return $this->returnRes(true, $responseData["msg"], $responseData);
} else {
return $this->returnRes(false, ($responseData['sub_msg'] ?? $responseData['msg']), $resMapData);
}
} else {
echo "响应验签失败";
// echo "响应验签失败";
return $this->returnRes(false, "响应验签失败", []);

}
}

/**
* alipay.planet.ecocampus.api.debt.cancel(撤销欠款)
* @param $out_order_no string 外部订单号
* @param $merchant_code string 商户编号
* @return array
*/
public function alipayPlanetEcocampusApiDebtCancel($out_order_no, $merchant_code): array
{

// cleint初始
$client = new \EcoApiClient();

return [];
// 根据环境,选择行星OPENAPI网关地址
$client->gatewayUrl = $this->serverUrl;
$client->rsaPrivateKey = $this->privateKey;
$client->alipayrsaPublicKey = $this->alipayPublicKey;
$client->signType = $this->signType;
$client->format = $this->format;

// 业务参数
$bizContent["merchant_code"] = $merchant_code;
$bizContent["out_order_no"] = $out_order_no;

// 指定需要调用的service接口
$params["service"] = "alipay.planet.ecocampus.api.debt.cancel";
$params["request_id"] = "" . uuid();
$params["biz_content"] = json_encode($bizContent);
$params["version"] = "1.0";

// 其他参数
$params["charset"] = $this->charset;
$params["isv_app_id"] = $this->appId;
$params["utc_timestamp"] = "" . msectime();

//获取签名
$sign = $client->generateSign($params, $this->signType);

// 调用ECOAPI
$result = $client->call($params);

$jsonStr = json_encode($result);


// 响应的签名验证 转成Array 而非 Object
$resMapData = json_decode($jsonStr, true);
$this->logger($resMapData, 'alipayPlanetEcocampusApiDebtRepay', true);

// 验签
$verifyRes = checkResponse($resMapData, $client->alipayrsaPublicKey);

if ($verifyRes) {
// echo "响应验签成功";
$responseData = $resMapData["response"];
if ($responseData['code'] == 10000) {
return $this->returnRes(true, $responseData["msg"], $responseData);
} else {
return $this->returnRes(false, ($responseData['sub_msg'] ?? $responseData['msg']), $resMapData);
}
} else {
// echo "响应验签失败";
return $this->returnRes(false, "响应验签失败", []);

}
}

}
@@ -108,7 +311,7 @@ function checkResponse($res, $pubKey)
{

$resSignType = $res['sign_type'];
if($resSignType != "RSA2"){
if ($resSignType != "RSA2") {
return false;
}

@@ -116,7 +319,7 @@ function checkResponse($res, $pubKey)

$data = $res["response"];
nestKsort($data);
$data = json_encode($data,JSON_UNESCAPED_UNICODE);
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
$data = str_replace("[]", "{}", $data);

$pubKey = "-----BEGIN PUBLIC KEY-----\n" .
@@ -125,7 +328,7 @@ function checkResponse($res, $pubKey)
$pubKey = openssl_get_publickey($pubKey);

$resSign = base64_decode($resSign);
$result = (bool)openssl_verify($data, $resSign, $pubKey, OPENSSL_ALGO_SHA256);
$result = (bool)openssl_verify($data, $resSign, $pubKey, OPENSSL_ALGO_SHA256);
return $result;
}

@@ -155,10 +358,10 @@ function msectime()
/**
* 生成UUID
*/
function uuid()
function uuid()
{
$chars = md5(uniqid(mt_rand(), true));
$uuid = substr($chars, 0, 8) . '-'
$uuid = substr($chars, 0, 8) . '-'
. substr($chars, 8, 4) . '-'
. substr($chars, 12, 4) . '-'
. substr($chars, 16, 4) . '-'


+ 2
- 2
src/common/Service/AliBPass/demo/EcoApiClient.php View File

@@ -57,8 +57,8 @@ class EcoApiClient
$sysParams["sign"] = $this->generateSign($sysParams, "RSA2");

// TODO 请删除
echo "<br/>=========== 请求参数 ===========<br/>";
var_dump($sysParams);
// echo "<br/>=========== 请求参数 ===========<br/>";
// var_dump($sysParams);


//网关地址


Loading…
Cancel
Save