diff --git a/src/addon/huaweipay/event/Install.php b/src/addon/huaweipay/event/Install.php new file mode 100644 index 000000000..51161c5ed --- /dev/null +++ b/src/addon/huaweipay/event/Install.php @@ -0,0 +1,17 @@ +getPayConfig($params[ 'site_id' ] ?? 1); + $config = $config_result[ "data" ][ "value" ] ?? []; + $pay_status = $config[ "pay_status" ] ?? 0; + + $app_type = $params['app_type'] ?? ''; if (!empty($app_type)) { - if (!in_array($app_type, [ "h5", "app", "pc", "hwapp" ])) { + $app_type_array = [ 'h5', 'wechat', 'weapp', 'pc', 'app', 'hwapp']; + if (!in_array($app_type, $app_type_array)) { return ''; } - - $config_model = new Config(); - $config_result = $config_model->getPayConfig($param[ 'site_id' ]); - $config = $config_result[ "data" ][ "value" ] ?? []; - $pay_status = $config[ "pay_status" ] ?? 0; if ($pay_status == 0) { return ''; } @@ -37,8 +38,10 @@ class PayType "edit_url" => "huaweipay://shop/pay/config", "shop_url" => "huaweipay://shop/pay/config", "logo" => "addon/huaweipay/icon.png", - "desc" => "华为支付(www.huawei.com) 是华为公司提供的网上支付平台。" + "desc" => "华为支付(www.huawei.com) 是华为公司提供的网上支付平台。", + "pay_status" => $pay_status, ); return $info; + } } diff --git a/src/addon/huaweipay/event/TransferType.php b/src/addon/huaweipay/event/TransferType.php index 6c5ce03c0..8b2439b17 100644 --- a/src/addon/huaweipay/event/TransferType.php +++ b/src/addon/huaweipay/event/TransferType.php @@ -4,17 +4,32 @@ */ namespace addon\huaweipay\event; +use addon\huaweipay\model\config; /** - * 转账类型 + * 转账类型 (前后台调用) */ class TransferType { /** * 转账类型处理 */ - public function handle($param) + public function handle($params) { + $app_type = $params['app_type'] ?? ''; + if (!empty($app_type)) { + $config_model = new Config(); + $app_type_array = $config_model->app_type; + if (!in_array($app_type, $app_type_array)) { + return ''; + } + $config_result = $config_model->getPayConfig($params[ 'site_id' ]); + $config = $config_result[ "data" ][ "value" ] ?? []; + $transfer_status = $config[ "transfer_status" ] ?? 0; + if ($transfer_status == 0) { + return ''; + } + } $info = array ( "pay_type" => "huaweipay", "pay_type_name" => "华为支付", diff --git a/src/addon/huaweipay/event/UnInstall.php b/src/addon/huaweipay/event/UnInstall.php new file mode 100644 index 000000000..e2fac841d --- /dev/null +++ b/src/addon/huaweipay/event/UnInstall.php @@ -0,0 +1,17 @@ +getPayConfig($site_id)[ 'data' ][ 'value' ] ?? []; + $original_config = $this->getPayConfig($site_id)['data']['value'] ?? []; // 检测数据是否发生变化,如果没有变化,则保持未加密前的数据 - if (!empty($data[ 'app_id' ]) && $data[ 'app_id' ] == $this->encrypt) { - $data[ 'app_id' ] = $original_config[ 'app_id' ]; // 应用ID - } - if (!empty($data[ 'private_key' ]) && $data[ 'private_key' ] == $this->encrypt) { - $data[ 'private_key' ] = $original_config[ 'private_key' ]; // 应用私钥 - } - if (!empty($data[ 'public_key' ]) && $data[ 'public_key' ] == $this->encrypt) { - $data[ 'public_key' ] = $original_config[ 'public_key' ]; // 应用公钥 - } - if (!empty($data[ 'huawei_public_key' ]) && $data[ 'huawei_public_key' ] == $this->encrypt) { - $data[ 'huawei_public_key' ] = $original_config[ 'huawei_public_key' ]; // 华为公钥 + // 定义一个数组,用于存储需要加密的字段 + $encrypt_fields = $this->encrypt_fields; + $is_change = false; + + // 遍历需要加密的字段 + foreach ($encrypt_fields as $field) { + if (!empty($data[$field]) && $data[$field] == $this->encrypt) { + $data[$field] = $original_config[$field]; // 应用ID + $is_change = true; + } } - $res = $config->setConfig($data, '华为支付配置', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'HUAWEI_PAY_CONFIG' ] ]); + $res = $config->setConfig($data, '华为支付配置', 1, [['site_id', '=', $site_id], ['app_module', '=', $app_module], ['config_key', '=', 'HUAWEI_PAY_CONFIG']]); return $res; } @@ -58,20 +71,16 @@ class Config extends BaseModel public function getPayConfig($site_id = 0, $app_module = 'shop', $need_encrypt = false) { $config = new ConfigModel(); - $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'HUAWEI_PAY_CONFIG' ] ]); + $res = $config->getConfig([['site_id', '=', $site_id], ['app_module', '=', $app_module], ['config_key', '=', 'HUAWEI_PAY_CONFIG']]); if ($need_encrypt) { // 加密敏感信息 - if (!empty($res[ 'data' ][ 'value' ][ 'app_id' ])) { - $res[ 'data' ][ 'value' ][ 'app_id' ] = $this->encrypt; // 应用ID - } - if (!empty($res[ 'data' ][ 'value' ][ 'private_key' ])) { - $res[ 'data' ][ 'value' ][ 'private_key' ] = $this->encrypt; // 应用私钥 - } - if (!empty($res[ 'data' ][ 'value' ][ 'public_key' ])) { - $res[ 'data' ][ 'value' ][ 'public_key' ] = $this->encrypt; // 应用公钥 - } - if (!empty($res[ 'data' ][ 'value' ][ 'huawei_public_key' ])) { - $res[ 'data' ][ 'value' ][ 'huawei_public_key' ] = $this->encrypt; // 华为公钥 + $encrypt_fields = $this->encrypt_fields; + + // 遍历需要加密的字段 + foreach ($encrypt_fields as $field) { + if (!empty($res['data']['value'][$field])) { + $res['data']['value'][$field] = $this->encrypt; // 加密敏感信息 + } } } return $res; diff --git a/src/addon/huaweipay/shop/controller/Pay.php b/src/addon/huaweipay/shop/controller/Pay.php index 296f634f8..697f54c6d 100644 --- a/src/addon/huaweipay/shop/controller/Pay.php +++ b/src/addon/huaweipay/shop/controller/Pay.php @@ -25,7 +25,8 @@ class Pay extends BaseShop $mch_auth_id = input("mch_auth_id", "");//商户证书id, // PETALPAY.MERC_AUTH_ID, 商户证书id $sign_type = input("sign_type", "RSA");//商户公私钥签名类型, // PETALPAY.SIGN_TYPE, 签名类型, 默认使用RSA $huawei_public_key = input("huawei_public_key", ""); //华为公钥, // PETALPAY.HW_PAY_PUBLIC_KEY_FOR_CALLBACK, 华为公钥 - $app_type = input("app_type", "");//支持端口 如web app + $huawei_public_key_for_sessionkey = input("huawei_public_key_for_sessionkey", ""); //华为公钥, // PETALPAY.HW_PAY_PUBLIC_KEY_FOR_SESSIONKEY, 华为公钥 + $enable_app_types = input("enable_app_types", '');//支持端口 如web app,app // PETALPAY.ENABLE_APP_TYPES, 支持的支付端口 $pay_status = input("pay_status", 0);//支付启用状态 $refund_status = input("refund_status", 0);//退款启用状态 $transfer_status = input("transfer_status", 0);//转账启用状态 @@ -37,10 +38,11 @@ class Pay extends BaseShop "mch_auth_id" => $mch_auth_id, "sign_type" => $sign_type, "huawei_public_key" => $huawei_public_key, + "huawei_public_key_for_sessionkey" => $huawei_public_key_for_sessionkey, "refund_status" => $refund_status, "pay_status" => $pay_status, "transfer_status" => $transfer_status, - "app_type" => $app_type + "enable_app_types" => $enable_app_types ); $result = $config_model->setPayConfig($data, $this->site_id, $this->app_module); return $result; @@ -48,15 +50,15 @@ class Pay extends BaseShop $info = $config_model->getPayConfig($this->site_id, $this->app_module, true)[ 'data' ][ 'value' ] ?? []; if (!empty($info)) { - $app_type_arr = []; - if (!empty($info[ 'app_type' ])) { - $app_type_arr = explode(',', $info[ 'app_type' ]); + $enable_app_type_arr = []; + if (!empty($info[ 'enable_app_types' ])) { + $enable_app_type_arr = explode(',', $info[ 'enable_app_types' ]); } - $info[ 'app_type_arr' ] = $app_type_arr; + $info[ 'enable_app_type_arr' ] = $enable_app_type_arr; // 当前支持的支付端口 } $this->assign("info", $info); - $this->assign("app_type", Config::get("app_type")); - + $this->assign("support_app_types", Config::get("app_type")); // 获取所有支持的支付端口 + return $this->fetch("pay/config"); } } @@ -66,17 +68,17 @@ class Pay extends BaseShop */ public function uploadHuaweiCrt() { - $upload_model = new Upload(); - $site_id = request()->siteid(); + $site_id = request()->siteid(); + $upload_model = new Upload($site_id); + $name = input("name", ""); - $extend_type = [ 'crt', 'pem' ]; + $extend_type = [ 'pem' ]; $param = array ( "name" => "file", "extend_type" => $extend_type ); - $site_id = max($site_id, 0); - $result = $upload_model->setPath("common/huaweipay/crt/" . $site_id . "/")->file($param); + $result = $upload_model->setPath("common/huaweipay/cert/")->file($param); return $result; } } diff --git a/src/addon/huaweipay/shop/view/pay/config.html b/src/addon/huaweipay/shop/view/pay/config.html index 0d8b5537b..68e652936 100644 --- a/src/addon/huaweipay/shop/view/pay/config.html +++ b/src/addon/huaweipay/shop/view/pay/config.html @@ -5,7 +5,7 @@
已上传
+已上传✅
{else/}未上传
{/notempty} @@ -38,7 +38,7 @@已上传
+已上传✅
{else/}未上传
{/notempty} @@ -63,10 +63,10 @@已上传
+已上传✅
{else/}未上传
{/notempty} @@ -80,32 +80,32 @@