public function aliPayReturn() { Log::pay('ali wap pay return raw data: ' . json_encode($_GET, JSON_UNESCAPED_UNICODE)); $orderId = $this->getParam('orderId', ''); if (empty($orderId)) { // ; } $this->display('alipay_return'); }
private function doOpt($data) { switch ($data['opt']) { case 'activate_for_gzh': WxUserModel::onActivateForGZH($data['data']['openid']); break; default: Log::error('wx event async job: unknow event'); } }
private function onSubscribe($openid, $from) { $wxUserInfo = WxSDK::getUserInfo($openid, 'snsapi_base'); if (empty($wxUserInfo)) { Log::warng('first get wxuinfo:' . $openid . ' userinfo fail from ' . $from); $wxUserInfo = WxSDK::getUserInfo($openid, 'snsapi_base'); if (empty($wxUserInfo)) { Log::warng('second get wxuinfo:' . $openid . ' userinfo fail from ' . $from); return false; } } $userInfo = WxUserModel::findUserByOpenId($openid); if (empty($userInfo)) { WxUserModel::newOne($wxUserInfo, $from); } else { WxUserModel::updateWxUserInfo($userInfo, $wxUserInfo, $from); } }
protected final function spawnTask($concurrentNum) { $childPids = array(); for ($i = 0; $i < $concurrentNum; $i++) { $childPid = pcntl_fork(); if ($childPid == -1) { Log::fatal('cli - fork fail!'); exit; } else { if ($childPid > 0) { // parent $childPids[] = $childPid; } else { // child $this->run($i); exit; } } } foreach ($childPids as $childPid) { $status = 0; pcntl_waitpid($childPid, $status); } }
private static function genCategoryId($categoryId) { $level1 = (int) ($categoryId / 1000000); $level2 = (int) ((int) ($categoryId / 1000) % 1000); $level3 = (int) ($categoryId % 1000); if ($level1 == 0) { // 增加一级分类 $sql = 'select max(category_id) as m from g_category'; $ret = DB::getDB('w')->rawQuery($sql); if ($ret === false) { return false; } if (empty($ret) || empty($ret[0]['m'])) { return 100000000; // 初始以100000000开始,虽然会少用9个,但会整齐好看一些 } $max = (int) $ret[0]['m']; if ((int) ($max / 1000000) == 999) { Log::fatal('category_id ' . $categoryId . ' level1 max = 999, out of limit!'); return false; } return ((int) ($max / 1000000) + 1) * 1000000; } else { if ($level2 == 0 && $level3 == 0) { // 增加二级分类 $sql = 'select max(category_id) as m from g_category where' . ' category_id >= ' . $level1 * 1000000 . ' and category_id < ' . ($level1 + 1) * 1000000; $ret = DB::getDB('w')->rawQuery($sql); if ($ret === false) { return false; } if (empty($ret) || empty($ret[0]['m'])) { return $level1 * 1000000 + 1000; } $maxLevel2 = (int) ((int) $ret[0]['m'] / 1000) % 1000; if ($maxLevel2 == 999) { Log::fatal('category_id ' . $categoryId . ' level2 max = 999, out of limit!'); return false; } return $level1 * 1000000 + ($maxLevel2 + 1) * 1000; } else { if ($level3 == 0) { // 增加三级分类 $sql = 'select max(category_id) as m from g_category where' . ' category_id >= ' . ($level1 * 1000000 + $level2 * 1000) . ' and category_id < ' . ($level1 * 1000000 + ($level2 + 1) * 1000); $ret = DB::getDB('w')->rawQuery($sql); if ($ret === false) { return false; } if (empty($ret) || empty($ret[0]['m'])) { return $level1 * 1000000 + $level2 * 1000 + 1; } $maxLevel3 = (int) $ret[0]['m'] % 1000; if ($maxLevel3 == 999) { Log::fatal('category_id ' . $categoryId . ' level3 max = 999, out of limit!'); return false; } return $level1 * 1000000 + $level2 * 1000 + $maxLevel3 + 1; } } } Log::error('error category_id(' . $categoryId . ') when generate category id'); return false; }
public static function firstSend($smsPhones, $smsContent) { $url = 'http://si.800617.com:4400/SendSms.aspx?un=xxx&pwd=xxx' . '&mobile=' . $smsPhones . '&msg=' . urlencode(iconv('utf-8', 'gb2312', $smsContent)); $beginTime = microtime(true); $ret = HttpUtil::request($url, false, false, 3); $diff = round(microtime(true) - $beginTime, 3); if ((double) $diff > 1.5) { Log::warng('second smsservice - escape long time ' . $diff); } if ($ret === false) { return false; } if (strpos($ret, '=1&') !== false) { return true; } if (strpos($ret, '=-11&') !== false) { // 无余额 AsyncModel::monitor('短信余额不足', '首选短信运营商余额不足'); return false; } return false; }
private function toWxLogin() { $openInfo = WxSDK::getOpenInfo('snsapi_base', WX_APP_ID, WX_APP_SECRET); if (empty($openInfo['openid'])) { // TODO 这里要显示的告诉用户 // header('Location: /TODO'); // exit(0); return false; } $wxUserInfo = WxSDK::getUserInfo($openInfo['openid'], 'snsapi_base'); if (empty($wxUserInfo)) { // Log::warng('first get wxuinfo:' . $openInfo['openid'] . ' fail when autologin'); $wxUserInfo = WxSDK::getUserInfo($openInfo['openid'], 'snsapi_base'); if (empty($wxUserInfo)) { // Log::warng('second get wxuinfo:' . $openInfo['openid'] . ' fail when autologin'); // TODO 这里要显示的告诉用户 // header('Location: /TODO'); // exit(0); return false; } } $wxDBUserInfo = WxUserModel::findUserByOpenId($openInfo['openid']); if (empty($wxDBUserInfo)) { // new one $from = WxUserModel::SUBSCRIBE_FROM_ALREADY; if ((int) $wxUserInfo['subscribe'] == 0) { $from = WxUserModel::SUBSCRIBE_FROM_UNSUBSCRIBE; } $ret = WxUserModel::newOne($wxUserInfo, $from); if ($ret === false) { // TODO 这里要显示的告诉用户 // header('Location: /TODO'); // exit(0); return false; } } return $openInfo['openid']; }
private function toWxLogin() { $openInfo = WxSDK::getOpenInfo('snsapi_base', WX_APP_ID, WX_APP_SECRET); if (empty($openInfo['openid'])) { // TODO 这里要显示的告诉用户 // header('Location: /TODO'); // exit(0); return; } $wxUserInfo = WxSDK::getUserInfo($openInfo['openid'], 'snsapi_base'); if (empty($wxUserInfo)) { // Log::warng('first get wxuinfo:' . $openInfo['openid'] . ' fail when autologin'); $wxUserInfo = WxSDK::getUserInfo($openInfo['openid'], 'snsapi_base'); if (empty($wxUserInfo)) { // Log::warng('second get wxuinfo:' . $openInfo['openid'] . ' fail when autologin'); // TODO 这里要显示的告诉用户 // header('Location: /TODO'); // exit(0); return; } } $ret = WxUserModel::findUserByOpenId($openInfo['openid']); if (!empty($ret)) { $this->doLoginInWx($openInfo['openid']); return; } else { // create one $from = WxUserModel::SUBSCRIBE_FROM_ALREADY; if ((int) $wxUserInfo['subscribe'] == 0) { $from = WxUserModel::SUBSCRIBE_FROM_UNSUBSCRIBE; } $ret = WxUserModel::newOne($wxUserInfo, $from); if ($ret === false) { // TODO 这里要显示的告诉用户 // header('Location: /TODO'); // exit(0); return; } $ret = $this->doLoginInWx($openInfo['openid']); if ($ret === false) { Log::error("create wx user fail! " . json_encode($wxUserInfo, JSON_UNESCAPED_UNICODE)); // TODO 这里要显示的告诉用户 // header('Location: /TODO'); // exit(0); } } }
public function aliPay() { if ($_SERVER['REQUEST_METHOD'] != 'POST') { exit; } if (!isset($_POST['sign']) || !isset($_POST['sign_type']) || $_POST['sign_type'] != 'RSA') { echo 'fail'; exit; } $ret = AliSDK::verifySign($_POST, CONFIG_PATH . '/alipay/alipay_public_key.pem', $_POST['sign']); $ret = true; // TODO if ($ret === false) { Log::pay('ali wap pay notify fail (sign fail) ' . json_encode($_POST, JSON_UNESCAPED_UNICODE)); echo 'success'; exit; } if (!empty($_POST['notify_id'])) { $ret = AliSDK::verifyNotify(ALI_PAY_PARTNER_ID, CONFIG_PATH . '/alipay/cacert.pem', $_POST['notify_id']); if ($ret === false) { Log::pay('ali wap pay notify fail (verify notify_id fail) ' . json_encode($_POST, JSON_UNESCAPED_UNICODE)); echo 'fail'; exit; } } $nk = Nosql::NK_PAY_NOTIFY_DE_DUPLICATION . $data['out_trade_no']; $nk = Nosql::get($nk); if (!empty($nk)) { Log::pay('ali wap pay notify success (had handled): ' . json_encode($_POST, JSON_UNESCAPED_UNICODE)); echo 'success'; return; } if ($_POST['trade_status'] == 'TRADE_SUCCESS') { if ($this->onPayNotifyOk($_POST['out_trade_no'], $_POST['total_fee'], $_POST['total_fee']) === true) { Nosql::setex($nk, Nosql::NK_PAY_NOTIFY_DE_DUPLICATION_EXPIRE, 'x'); Log::pay('ali wap pay notify success : ' . json_encode($_POST, JSON_UNESCAPED_UNICODE)); echo 'success'; return; } } else { // TRADE_FINISHED WAIT_BUYER_PAY 不处理 echo 'success'; return; } echo 'fail'; }