diff --git a/app/common.php b/app/common.php index e0af625..12bb700 100644 --- a/app/common.php +++ b/app/common.php @@ -1406,7 +1406,39 @@ if (!function_exists('getRandom')) { return floatval(number_format($rand,2)); } } - +// post请求 +if (!function_exists('curlPost')) { + function curlPost($url, $post_data = array(), $timeout = 5, $header = "", $data_type = "") { + $header = empty($header) ? [] : $header; + //支持json数据数据提交 + if($data_type == 'json'){ + $post_string = json_encode($post_data); + }elseif($data_type == 'array') { + $post_string = $post_data; + }elseif(is_array($post_data)){ + $post_string = http_build_query($post_data, '', '&'); + } + + $ch = curl_init(); // 启动一个CURL会话 + curl_setopt($ch, CURLOPT_URL, $url); // 要访问的地址 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查 // https请求 不验证证书和hosts + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在 + if(!empty($_SERVER['HTTP_USER_AGENT'])) curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器 + //curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 + //curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer + curl_setopt($ch, CURLOPT_POST, true); // 发送一个常规的Post请求 + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); // Post提交的数据包 + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // 设置超时限制防止死循环 + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); + //curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回 + curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //模拟的header头 + $result = curl_exec($ch); + curl_close($ch); + + return json_decode($result,true); + } +} diff --git a/app/common/model/common/HuiFu.php b/app/common/model/common/HuiFu.php new file mode 100644 index 0000000..10eb3f6 --- /dev/null +++ b/app/common/model/common/HuiFu.php @@ -0,0 +1,114 @@ +config = systemConfig(['hftx_switch', 'hftx_sys_id', 'hftx_product_id', 'hftx_wechat_name']); + if($this->config['hftx_switch'] != 1) throw new ValidateException('未开启当前支付!'); + } + + // 发起请求 + private function requestApi($data){ + try { + $params = [ + 'sys_id' => $this->config['hftx_sys_id'], + 'product_id' => $this->config['hftx_product_id'], + 'sign' => $this->getSign($data), + 'data' => $data + ]; + $header = [ + 'Content-Type: application/json; charset=utf-8', + 'Cache-Control: no-cache', + 'Pragma: no-cache' + ]; + $result = curlPost('https://api.huifu.com/v2/trade/payment/jspay',$params,30,$header,'json'); + + + + debug($result); + } catch (\Exception $e) { + // Log::info('汇付支付 - 错误: ' . $e->getMessage()); + throw new ValidateException('支付失败:' . $e->getMessage()); + } + } + // 获取签名 + private function getSign($data){ + ksort($data); + $data = json_encode($data, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE); + $rsaPrivateKey = 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDfzbAq3sH3ZGMLkECaWBqhOIkc1X7XrmLgzMVVZUPZ7iDfdswpQDOLaVuMfyTlj4MX3pl3GkWR13QzqNtpUXclIYuggqnqv9FIIoagSuqwhhyCcV6RBah/ci7uDmtA2+2Oc2gn2lyJw7Uih4W0sPLGQJR7nzw/PidstKkuE2xFxn4x8O4HJTiBohSDkZlt8ew6sefo2Qa8PukhU0IqS9uUMMk9OkWImFMfR7JqgR5OIsitZUaEw0+b6bS3PKyrrmrFVrBQgnww2ldufhWD4cGaDV+o4/q4sr+akpcbggei2uVf/g74DZY3VRk4HOFi18bfZXvYRjvvf+NkHl3VzjAjAgMBAAECggEBAJIUdu20kpTBEKkmkhRsd41OEqkgbXeoWt/yqMdRntUryocxypcOUdaogVoWT2YLo3y8Dh2gp1JHeJCTogt/Yi55U+MEBpa0d40HBCqyW7e3AfretuQf9lihliJKhRVDuC5oA88nh4lgleWg4dQMP5rJ4mFCkZeSIT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-----\n".wordwrap($rsaPrivateKey, 64, "\n", true)."\n-----END PRIVATE KEY-----"; + $signature= ''; + openssl_sign($data, $signature, $key, OPENSSL_ALGO_SHA256); + + return base64_encode($signature); + } + + + + // 微信小程序支付 + public function miniApp($user, $options){ + // 异步通知地址 + $siteUrl = systemConfig('site_url'); + $notifyUrl = $siteUrl.Route::buildUrl('notifyHuiFu')->build(); + // 获取用户openid + $wechatUserRepository = app()->make(WechatUserRepository::class); + $openId = $wechatUserRepository->idByRoutineId($user['wechat_user_id']); + $data = [ + 'req_date' => date("Ymd"),// 请求日期 + 'req_seq_id' => $options['order_sn'],// 请求流水号 128 + 'huifu_id' => $this->config['hftx_sys_id'],// 渠道与一级代理商的直属商户ID + 'goods_desc' => '一个苹果',// 商品描述 127 + 'trade_type' => 'T_MINIAPP', + 'trans_amt' => '0.01', // 交易金额 单位元,需保留小数点后两位,最低0.01 + 'notify_url' => $notifyUrl,// 交易异步通知地址,http或https开头。 + 'wx_data' => [ + 'openid' => 'oOtdH46-tpYgiTqPPxszMofl2V8Q',// 万马奔腾 - $openId, + 'appid' => 'wx10df35b8f8f07887',// saas - oOtdH46-tpYgiTqPPxszMofl2V8Q + // 'sub_appid' => 'wx7aac64d4d4419260',// 子商户公众账号id wx7aac64d4d4419260 + // 'sub_openid' => $openId, + ], + ]; + $result = $this->requestApi($data); + + + debug($data); + + + } + + + + + + + + + + + + + + +} diff --git a/app/controller/api/Common.php b/app/controller/api/Common.php index de09552..48f016d 100644 --- a/app/controller/api/Common.php +++ b/app/controller/api/Common.php @@ -94,30 +94,65 @@ class Common extends BaseController return app()->make(DiyRepository::class)->getThemeVar($type); } - public function config() - { + public function config(){ $config = Cache::remember('get_api_config',function(){ - $config = systemConfig(['open_update_info', 'store_street_theme', 'is_open_service', 'is_phone_login', 'global_theme', 'integral_status', 'mer_location', 'alipay_open', 'hide_mer_status', 'mer_intention_open', 'share_info', 'share_title', 'share_pic', 'store_user_min_recharge', 'recharge_switch', 'balance_func_status', 'yue_pay_status', 'site_logo', 'routine_logo', 'site_name', 'login_logo', 'procudt_increase_status', 'sys_extension_type', 'member_status', 'copy_command_status', 'community_status','community_reply_status','community_app_switch', 'withdraw_type', 'recommend_switch', 'member_interests_status', 'beian_sn', 'community_reply_auth','hot_ranking_switch','svip_switch_status','margin_ico','margin_ico_switch','first_avatar_switch','wechat_phone_switch','community_auth']); + $config = systemConfig([ + 'open_update_info', + 'store_street_theme', + 'is_open_service', + 'is_phone_login', + 'global_theme', + 'integral_status', + 'mer_location', + 'alipay_open', + 'hide_mer_status', + 'mer_intention_open', + 'share_info', + 'share_title', + 'share_pic', + 'store_user_min_recharge', + 'recharge_switch', + 'balance_func_status', + 'yue_pay_status', + 'site_logo', + 'routine_logo', + 'site_name', + 'login_logo', + 'procudt_increase_status', + 'sys_extension_type', + 'member_status', + 'copy_command_status', + 'community_status', + 'community_reply_status', + 'community_app_switch', + 'withdraw_type', + 'recommend_switch', + 'member_interests_status', + 'beian_sn', + 'community_reply_auth', + 'hot_ranking_switch', + 'svip_switch_status', + 'margin_ico', + 'margin_ico_switch', + 'first_avatar_switch', + 'wechat_phone_switch', + 'community_auth', + 'pay_routine_switch', + 'hftx_switch', + 'hftx_wechat_name' + ]); $cache = app()->make(CacheRepository::class)->search(['copyright_status', 'copyright_context', 'copyright_image', 'sys_intention_agree']); - - if (!isset($cache['sys_intention_agree'])) { - $cache['sys_intention_agree'] = systemConfig('sys_intention_agree'); - } + if (!isset($cache['sys_intention_agree'])) $cache['sys_intention_agree'] = systemConfig('sys_intention_agree'); $title = app()->make(UserSignRepository::class)->signConfig(); - if (!$title) { - $config['member_status'] = 0; - } - if (!is_array($config['withdraw_type'])) { - $config['withdraw_type'] = ['1', '2', '3']; - } - + if (!$title) $config['member_status'] = 0; + if (!is_array($config['withdraw_type'])) $config['withdraw_type'] = ['1', '2', '3']; $config['tempid'] = app()->make(SystemNoticeConfigRepository::class)->getSubscribe(); $config['global_theme'] = $this->getThemeVar($config['global_theme']); -// $config['navigation'] = app()->make(DiyRepository::class)->getNavigation(); - $config = array_merge($config, $cache); - return $config; + + return array_merge($config, $cache); }, 3600); + return app('json')->success($config); } @@ -606,11 +641,23 @@ class Common extends BaseController } + // 汇付天下 支付回调 + public function notifyHuiFu(){ + Log::info('汇付天下 - 支付回调:' . var_export($_REQUEST, true)); + try { + } catch (Exception $e) { + + Log::info('汇付天下 - 支付回调 - 失败:' . var_export([$e->getMessage(), $e->getFile() . ':' . $e->getLine()], true)); + } + } + + + } diff --git a/crmeb/services/PayService.php b/crmeb/services/PayService.php index 63d0eb4..9158753 100644 --- a/crmeb/services/PayService.php +++ b/crmeb/services/PayService.php @@ -5,6 +5,7 @@ namespace crmeb\services; +use app\common\model\common\HuiFu; use app\common\model\user\User; use app\common\repositories\wechat\WechatUserRepository; use think\exception\ValidateException; @@ -23,22 +24,20 @@ class PayService $this->options = $options; } - public function pay(?User $user) - { - $method = 'pay' . ucfirst($this->type); - if (!method_exists($this, $method)) { - throw new ValidateException('不支持该支付方式'); - } + public function pay(?User $user){ + // $method = 'pay' . ucfirst($this->type); + $method = camelize('pay' . '_' . $this->type); + if (!method_exists($this, $method)) throw new ValidateException('不支持该支付方式' . $method); + return $this->{$method}($user); } - public function payWeixin(User $user) - { + public function payWeixin(User $user){ $wechatUserRepository = app()->make(WechatUserRepository::class); $openId = $wechatUserRepository->idByOpenId($user['wechat_user_id']); - if (!$openId) - throw new ValidateException('请关联微信公众号!'); + if (!$openId) throw new ValidateException('请关联微信公众号!'); $config = WechatService::create()->jsPay($openId, $this->options['order_sn'], $this->options['pay_price'], $this->options['attach'], $this->options['body']); + return compact('config'); } @@ -52,8 +51,7 @@ class PayService { $wechatUserRepository = app()->make(WechatUserRepository::class); $openId = $wechatUserRepository->idByRoutineId($user['wechat_user_id']); - if (!$openId) - throw new ValidateException('请关联微信小程序!'); + if (!$openId) throw new ValidateException('请关联微信小程序!'); $config = MiniProgramService::create()->jsPay($openId, $this->options['order_sn'], $this->options['pay_price'], $this->options['attach'], $this->options['body']); return compact('config'); } @@ -89,4 +87,18 @@ class PayService $config = AlipayService::create($this->affect)->appPaymentPrepare($this->options['order_sn'], $this->options['pay_price'], $this->options['body']); return compact('config'); } + + // 汇付 - 微信小程序微信支付 + public function payHftxWeixin(User $user){ + + (new HuiFu())->miniApp($user, $this->options); + + + debug([$user,$this->options]); + } + + + + + } diff --git a/route/api.php b/route/api.php index 7dbec7f..c08c6bd 100644 --- a/route/api.php +++ b/route/api.php @@ -711,20 +711,20 @@ Route::group('api/', function () { //微信支付回调 Route::any('notice/wechat_combine_pay/:type', 'api.Common/wechatCombinePayNotify')->name('wechatCombinePayNotify'); Route::any('notice/routine_combine_pay/:type', 'api.Common/routineCombinePayNotify')->name('routineCombinePayNotify'); - Route::any('notice/callback', 'api.Common/deliveryNotify'); - //小程序支付回调 Route::any('notice/routine_pay', 'api.Common/routineNotify')->name('routineNotify'); //支付宝支付回调 Route::any('notice/alipay_pay/:type', 'api.Common/alipayNotify')->name('alipayNotify'); Route::any('getVersion', 'api.Common/getVersion')->name('getVersion'); + // 汇付天下支付回调 + Route::any('notify/hui_fu_tian_xia', 'api.Common/notifyHuiFu')->name('notifyHuiFu'); + //城市列表 Route::get('system/city/lst', 'merchant.store.shipping.City/getlist'); Route::get('v2/system/city/lst/:pid', 'merchant.store.shipping.City/lstV2'); Route::get('v2/system/city', 'merchant.store.shipping.City/cityList'); - //热门搜索 Route::get('common/hot_keyword', 'api.Common/hotKeyword')->append(['type' => 0]); //社区热门搜索