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 doRemindInWeinXin($orderInfo) { $wxUserInfo = WxUserModel::findUserByUserId($orderInfo['user_id']); if (empty($wxUserInfo['openid'])) { return; } if (time() - $wxUserInfo['atime'] < 48 * 3600) { $content = '亲,您有一个未支付订单,请您及时付款以免过期\\n\\n' . '<a href=\\"' . APP_URL_BASE . '/User/MyOrder/toPay' . '\\">' . '前往支付>>' . '</a>'; AsyncModel::asyncSendKfMsg($wxUserInfo['openid'], 'text', $content, 0); } }
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); } }
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); } } }