예제 #1
0
 /**
  * 更改任务状态
  * @param int $status
  * @param int $id
  * @param string $msg	状态描述
  * @param int $send_time
  */
 public function UpdateStatus($status, $id, $msg = NULL, $send_time = 0)
 {
     $tableInfo = array('status' => $status, 'msg' => $msg, 'last_send' => time());
     if ($send_time) {
         $tableInfo['send_time'] = $send_time;
     }
     if ($status == Task::ERROR) {
         $item = $this->get($id);
         $tableInfo['retry_count'] = $item['retry_count'] + 1;
     }
     if ($status == Task::OK) {
         $item = $this->get($id);
         $type_arr = explode('|', $item['type']);
         $thirdAccount = new ThirdAccount();
         $third = $thirdAccount->getThird($item['uid'], $type_arr[0], $type_arr[1]);
         $tableInfo['url'] = $third['url'];
     }
     return $this->update($tableInfo, array('id' => $id));
 }
예제 #2
0
$tasks = $task->GetExecTasks();
$taskIds = array_keys($tasks);
$task->UpdateStatus(Task::EXECING, $taskIds);
$thirdAccount = new ThirdAccount();
foreach ($tasks as $id => $item) {
    $type_arr = explode('|', $item['type']);
    if (str_contains($item['msg'], '验证码') || str_contains($item['msg'], 'valCodeError') || $type_arr[0] == 'qzone_simula') {
        if (time() - $item['last_send'] < 10 * 60) {
            continue;
        }
    }
    if (str_contains($item['msg'], '重复发送') || str_contains($item['msg'], '用户调用次数超过限制')) {
        $task->update(array('retry_count' => Task::RETRY_COUNT), array('id' => $id));
        continue;
    }
    $third = $thirdAccount->getThird($item['uid'], $type_arr[0], $type_arr[1]);
    if ($third && $third['valid'] == 1) {
        $api = Factory::CreateAPI2($type_arr[0], $type_arr[1], $third);
        if ($item['cat'] == 'weibo') {
            $ret = $api->upload($item['content'], $item['pic']);
        } else {
            $ret = $api->publish($item['title'], $item['content']);
        }
    } else {
        $ret = $third ? '账号绑定过期,尚未重新绑定' : '账号绑定已取消';
    }
    if ($ret === true) {
        $task->UpdateStatus(Task::OK, $id);
        echo "任务#{$id}:发送成功<br>\r\n";
    } else {
        if (str_contains($ret, '已过期')) {