diff --git a/src/applet/app/controllers/AliCallBackController.php b/src/applet/app/controllers/AliCallBackController.php index 5051c48..b00dd21 100644 --- a/src/applet/app/controllers/AliCallBackController.php +++ b/src/applet/app/controllers/AliCallBackController.php @@ -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 = [ diff --git a/src/applet/app/controllers/Alipay/BPassController.php b/src/applet/app/controllers/Alipay/BPassController.php index 2d8863f..c2ca7a9 100644 --- a/src/applet/app/controllers/Alipay/BPassController.php +++ b/src/applet/app/controllers/Alipay/BPassController.php @@ -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, '提交方式错误!')); + } + } + } diff --git a/src/common/Model/SelfSupportForSchoolInfo.php b/src/common/Model/SelfSupportForSchoolInfo.php index 44297a5..85b7471 100644 --- a/src/common/Model/SelfSupportForSchoolInfo.php +++ b/src/common/Model/SelfSupportForSchoolInfo.php @@ -18,6 +18,12 @@ class SelfSupportForSchoolInfo extends BasicModel */ public $enterprise_id; + /** + * + * @var int + */ + public $user_identity_id; + /** * * @var string diff --git a/src/common/Service/AliBPass/AliEcoService.php b/src/common/Service/AliBPass/AliEcoService.php deleted file mode 100644 index f21c1a5..0000000 --- a/src/common/Service/AliBPass/AliEcoService.php +++ /dev/null @@ -1,87 +0,0 @@ -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()); - } - } - -} \ No newline at end of file diff --git a/src/common/Service/AliBPass/AliEcoServiceBack.php b/src/common/Service/AliBPass/AliEcoServiceBack.php deleted file mode 100644 index 8ca3d20..0000000 --- a/src/common/Service/AliBPass/AliEcoServiceBack.php +++ /dev/null @@ -1,112 +0,0 @@ -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()); - } - } - -} \ No newline at end of file diff --git a/src/common/Service/AliBPass/demo/AliEcoService.php b/src/common/Service/AliBPass/demo/AliEcoService.php index 4a89728..6276bac 100644 --- a/src/common/Service/AliBPass/demo/AliEcoService.php +++ b/src/common/Service/AliBPass/demo/AliEcoService.php @@ -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) . '-' diff --git a/src/common/Service/AliBPass/demo/EcoApiClient.php b/src/common/Service/AliBPass/demo/EcoApiClient.php index c0959b8..9a725cc 100644 --- a/src/common/Service/AliBPass/demo/EcoApiClient.php +++ b/src/common/Service/AliBPass/demo/EcoApiClient.php @@ -57,8 +57,8 @@ class EcoApiClient $sysParams["sign"] = $this->generateSign($sysParams, "RSA2"); // TODO 请删除 - echo "
=========== 请求参数 ===========
"; - var_dump($sysParams); +// echo "
=========== 请求参数 ===========
"; +// var_dump($sysParams); //网关地址