/** * 获取创业家下所有应用系统设置COOKIE接口地址 */ public function actionAppCookie() { // 获取JS回调函数 $callback = Yii::$app->getRequest()->get('callback'); $is_register = Yii::$app->getRequest()->get('is_register') ?: 0; try { $info = null; $userModel = new UserBaseInfo(); $userInfo = $userModel->getUserInfoCache(); if (isset($userInfo['id']) && $userInfo['id']) { $user = $userModel->getUserById($userInfo['id']); $info['openid'] = $user['open_id']; $info['mobile'] = $user['mobile']; $info['email'] = $user['email']; $info['password_salt'] = $user['password_salt']; $info['password'] = $user['password']; $info['username'] = $user['username']; if ($is_register) { $info['is_register'] = $is_register; $info['salt'] = $user['password_salt']; $info['password'] = $user['password']; } $json = json_encode($info); // 记录日志 $logger = FileLogger::getInstance('sso_' . date('Ymd') . '.log'); $encrypt = AsymmetryCrypt::opensslPublicEncrypt($json, dirname(Yii::$app->getBasePath()) . '/common/rsa_public_key.pem'); // $logger->writeOne($json . '====' . $encrypt, Logger::LEVEL_INFO,'SSO-IHEIMA'); // TODO:: +/ 替换成 +_ $encrypt = str_replace('+/', '+_', $encrypt); $encrypt = rawurlencode($encrypt); $logger->writeOne($json . '====' . $encrypt, Logger::LEVEL_INFO, 'SSO-IHEIMA'); $thinksns = AsymmetryCrypt::opensslPublicEncrypt($json, dirname(Yii::$app->getBasePath()) . '/common/rsa_key/100003/rsa_public_key.pem'); $thinksns = rawurlencode($thinksns); // TODO:: 获取应用系统COOKIE接口地址 $appCookie = ['code' => 0, 'sso' => [Url::toRoute(['sso/index'], true), 'http://app.iheima.net/?app=ihminterface&controller=index&action=ihmlogin&c=' . $encrypt, 'http://dev-group.chuangyejia.com/index.php?app=public&mod=Passport&act=grouplogin&c=' . $thinksns, 'http://test-group.chuangyejia.com/index.php?app=public&mod=Passport&act=grouplogin&c=' . $thinksns, 'http://group.chuangyejia.com/index.php?app=public&mod=Passport&act=grouplogin&c=' . $thinksns, 'http://cyj.zhiyicx.com/index.php?app=public&mod=Passport&act=grouplogin&c=' . $thinksns, 'http://group-t.chuangyejia.com/index.php?app=public&mod=Passport&act=grouplogin&c=' . $thinksns], 'msg' => []]; echo $callback . '(' . json_encode($appCookie) . ')'; } else { echo $callback . '(' . json_encode(['code' => 1, 'msg' => '用户未登录']) . ')'; } } catch (Exception $ex) { // TODO:: 异常处理 echo $callback . '(' . json_encode(['code' => 2, 'msg' => '系统繁忙,请稍后重试']) . ')'; } }
/** * 获取个应用系统登录接口地址 * * @param bool $is_register true 表示注册 * @return array|null * @throws \yii\base\Exception */ public function getCookieUrl($is_register = false) { $cookieUrl = null; $appId = null; $info = null; $userModel = new UserBaseInfo(); $userInfo = $userModel->getUserInfoCache(); $sso = SsoSettingInfo::findAll(); if ($sso) { foreach ($sso as $k => $val) { if (isset($val['log_out']['sign_in']) && $val['log_out']['sign_in']) { $cookieUrl[] = $val['log_out']['sign_in']; $appId[] = $val['app_id']; } } } if (isset($userInfo['id']) && $userInfo['id'] && $cookieUrl) { $user = $userModel->getUserById($userInfo['id']); $info['openid'] = $user['open_id']; $info['mobile'] = $user['mobile']; $info['email'] = $user['email']; if ($is_register) { $info['is_register'] = $is_register; $info['salt'] = $user['password_salt']; $info['password'] = $user['password']; } $info = json_encode($info); foreach ($cookieUrl as $key => &$url) { $appDir = $appId[$key]; $encrypt = AsymmetryCrypt::opensslPublicEncrypt($info, dirname(Yii::$app->getBasePath()) . '/common/rsa_key/' . $appDir . '/rsa_public_key.pem'); // TODO:: 为解决 +/ 丢失 / bug,临时解决方案 $encrypt = str_replace('+/', '+_', $encrypt); $encrypt = rawurlencode($encrypt); $bool = filter_var($url, FILTER_VALIDATE_URL); if ($bool === false) { unset($cookieUrl[$key]); continue; } $path = parse_url($url); if (!isset($path['query'])) { $url .= '?c=' . $encrypt; continue; } $query = queryToArray($path['query']); $query['c'] = $encrypt; $query_params = arrayToQuery($query); $url = $path['scheme'] . '://' . $path['host'] . '?' . $query_params; } shuffle($cookieUrl); return $cookieUrl; } else { return null; } }
/** * 二维码支付 */ public function actionNative() { $request = Yii::$app->getRequest(); $params = $request->get(); if (!isset($params['signature']) || !$params['signature']) { // TODO:: 必须传递签名参数 return; } $signature = rawurldecode($params['signature']); unset($params['signature']); $data = arrayToQuery($params); $file = dirname(Yii::$app->getBasePath()) . '/common/rsa_key/signature/public_key.pem'; $result = AsymmetryCrypt::verifySign($data, $signature, $file); if (!$result) { return; } $notifyUrl = Url::toRoute(['wxpay/notify'], true); $notify = new NativePay(); $url = ''; //模式一 /** * 流程: * 1、组装包含支付信息的url,生成二维码 * 2、用户扫描二维码,进行支付 * 3、确定支付之后,微信服务器会回调预先配置的回调地址,在【微信开放平台-微信支付-支付配置】中进行配置 * 4、在接到回调通知之后,用户进行统一下单支付,并返回支付信息以完成支付(见:native_notify.php) * 5、支付完成之后,微信服务器会通知支付成功 * 6、在支付成功通知中需要查单确认是否真正支付成功(见:notify.php) */ //$url = $notify->GetPrePayUrl("123456789"); //模式二 /** * 流程: * 1、调用统一下单,取得code_url,生成二维码 * 2、用户扫描二维码,进行支付 * 3、支付完成之后,微信服务器会通知支付成功 * 4、在支付成功通知中需要查单确认是否真正支付成功(见:notify.php) */ $input = new WxPayUnifiedOrder(); $input->SetBody($params['product_name']); if (isset($params['attach'])) { $input->SetAttach($params['attach']); } $input->SetOut_trade_no($params['order_sn']); $input->SetTotal_fee($params['turnover'] * 100); $input->SetTime_start(date('YmdHis', $params['create_time'])); $input->SetTime_expire(date('YmdHis', $params['expires_time'])); if (isset($params['product_desc'])) { $input->SetGoods_tag($params['product_desc']); } $input->SetNotify_url($notifyUrl); $input->SetTrade_type("NATIVE"); $input->SetProduct_id($params['product_id']); $result = $notify->GetPayUrl($input); $url = $result["code_url"]; $qrCode = new QrCode(); $qrCode->setText($url)->setSize(100)->setPadding(10)->setErrorCorrection('high')->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0))->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0))->setLabel('')->setLabelFontSize(16)->render(); }