input('uid'); if(empty($uid)){ return response()->error('PARAM_EMPTY'); } $channel_id = $this->getChannelId(); if(empty($channel_id)){ return response()->error('PARAM_EMPTY'); } $data = UserService::getById($uid); if(!$data){ return response()->error('USER_NOT_FOUND'); } if($data->distribution_channel_id != $channel_id){ return response()->error('USER_NOT_FOUND'); } //关注 $forceSubscribe = ForceSubscribeService::forceSubscribeUsersByUidIncludeCancel(['uid'=>$uid]); if($forceSubscribe){ $data->is_subscribed = $forceSubscribe->is_subscribed; $data->subscribed_time = date('Y-m-d H:i:s',strtotime($forceSubscribe->created_at)); $official_info = OfficialAccountService::officialAccountByAppid(['appid'=>$forceSubscribe->appid]); if($official_info){ $data->subscribe_official = $official_info->nickname; }else{ $data->subscribe_official = ''; } $data->subscribed_src = $official_info->qrcode_url; //$this->getRcodeInfo(['appid'=>$forceSubscribe->appid],$forceSubscribe->bid,$uid); $data->label = ''; if($forceSubscribe->bid){ $book_info = BookConfigService::getBookById($forceSubscribe->bid); if($book_info) $data->label = $book_info->category_name; } if($forceSubscribe->is_subscribed == 1){ $data->is_subscribed_text = '已关注'; }else{ $data->is_subscribed_text = '取关'; } }else{ $data->label = ''; $data->is_subscribed = -1; $data->is_subscribed_text = '未关注'; $data->subscribed_time = ''; $data->subscribe_official = ''; $data->subscribed_src = ''; } $charge_lists = OrderService::totalChargeList($uid); $total_charge = 0; $total_money = 0; if($charge_lists){ foreach ($charge_lists as $v){ $total_charge += 100*$v->price+$v->given; $total_money += $v->price; } } $data->total_charge = number_format($total_charge); $data->balance = number_format($data->balance); $chapter_consume = ChapterOrderService::getChapterTotalConsume($uid); $book_consume = BookOrderService::getBookTotalConsume($uid); $data->total_consume = number_format($chapter_consume+$book_consume); $data->total_get = 0; $data->total_money = $total_money; return response()->success($data); } protected function getRcodeInfo($param,$bid,$uid){ $param_need = [ 'gzh_app_id'=>$param['appid'], 'scene_id' =>$uid, 'timestamp'=>time(), ]; $param_need['sign'] = $this->getSign($param_need); $client = new Client(['timeout' => 3.0,]); try{ $qrcode_url_res = $client->request('get','http://zsyauth.aizhuishu.com/api/get_qrcode_url?'.http_build_query($param_need))->getBody()->getContents(); if($qrcode_url_res){ $qrcode_url = json_decode($qrcode_url_res,true); if($qrcode_url['code'] == 1){ //保存强关时的bid Redis::hset('force_subscribe_from_bid',$param['appid'].'_'.$this->uid,$bid); return $qrcode_url['data']; } } }catch (\Exception $e){ } return false; } /** * 公众号签名@华灯初上 * @param $params * @return string */ protected function getSign($params) { $url = $this->arr_to_url($params, false); $url = $url . '&key=' . $this->secret_key; $sign = md5($url); return $sign; } /** * 公众号签名@华灯初上 * @param $array * @param bool $has_sign * @return string */ protected function arr_to_url($array, $has_sign = false) { ksort($array); reset($array); $arg = ""; while (list ($name, $val) = each($array)) { if ($name == 'sign' && !$has_sign) continue; if (strpos($name, "_") === 0) continue; if (is_array($val)) $val = join(',', $val); if ($val === "") continue; $arg .= $name . "=" . $val . "&"; } $arg = substr($arg, 0, count($arg) - 2); return $arg; } }