准备工作

  1. 在Firefox中安装export-cookies插件 https://addons.mozilla.org/en-US/firefox/addon/export-cookies/

开始

  1. 打开Firefox,登录企业空间。http://upesn.com/
  2. 等候之后,菜单栏 -> 工具 -> Export cookies,然后选择一个位置,比如~/Downloads,会在这个目录下新建一个cookies.txt保存所有Cookie
  3. 打开Git Bash,参数参照
curl ... --cookie ~/Downloads/cookies.txt ...

定义变量

# Constants

PHYSIKID="6192702450860819471"
REFERER="http://upesn.com/space/home/index/VISITID/5417"
FILENAME="tumblr_of0mpcoCmq1so6p3jo1_500.jpg"

# Define variables

#cookie="Cookie: _adwr=5318519%230; gr_user_id=6f39ac86-df4b-40cf-8f7f-3fc9585918dc; Hm_lvt_bba24bf51c063b71e5ab0a1a720e5c00=1476060364; Hm_lpvt_bba24bf51c063b71e5ab0a1a720e5c00=1476060364; accountSet=5fea9f5a5bfd697a84f027c6cfcb995b; physikId=$PHYSIKID; memberId=2894773; _adwp=5318519.4289626662.1476060363.1476439239.1476451829.22; _adwc=5318519; Hm_lvt_a40a51907a6a6092c5c85e9f18600177=1476060364; Hm_lpvt_a40a51907a6a6092c5c85e9f18600177=1476453444; _adwb=5318519; gr_session_id_9b676ca07803bdc0=f16b505d-470e-4f57-a969-46e2322fbcef; gr_cs1_f16b505d-470e-4f57-a969-46e2322fbcef=member_id%3A2894773; ck_safe_chaoke_csrf_token=a3bf44c7bb4021102c6cb78f15bf9907; PHPSESSID=q2sdbug8jjg2pkm231171mklo6"

read -r -d '' common_header << EOM
  --cookie cookies.txt #-H "Cookie: $cookie" 
  -H 'Origin: http://upesn.com' 
  -H 'Accept-Encoding: gzip, deflate' 
  -H 'Accept-Language: en,zh-CN;q=0.8,zh;q=0.6,ja;q=0.4,tr;q=0.2,es;q=0.2,zh-TW;q=0.2,fr;q=0.2,ko;q=0.2,da;q=0.2,ru;q=0.2,sr;q=0.2,gl;q=0.2,it;q=0.2,nb;q=0.2,de;q=0.2' 
  -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36' 
EOM

上传图片

curl 'http://upesn.com/file/act/swfupload/fileFrom/15/gid/0/VISITID/5417' \
  $common_header \
  -H 'Accept: */*' \
  -H "Referer: $REFERER" \
  -H 'X-Requested-With: ShockwaveFlash/23.0.0.185' \
  -H 'Connection: keep-alive' \
  -F "Filename=$FILENAME" \
  -F "listType=1" \
  -F "sessid=q2sdbug8jjg2pkm231171mklo6" \
  -F "filedata=@$FILENAME" \
  -F "Upload=Submit Query" \
  --compressed -s > response.txt && cat response.txt

#["1717286","tumblr_of0mpcoCmq1so6p3jo1_500.jpg","1717963","http://staticoss.upesn.com/5417/2894773/201610/14/147645348214c2111d217d40fadc52f744c540805d.jpg.square.thumb.jpg","http://staticoss.upesn.com/5417/2894773/201610/14/147645348214c2111d217d40fadc52f744c540805d.jpg","ico_img_b"]

# Get file id from response
grep -o '".*"' response.txt | sed 's/",".*//g' | sed 's/"//g' > fids.txt
fids=`cat fids.txt` # 1717637
cat fids.txt

发言

curl 'http://upesn.com/speech/index/speechsub/VISITID/5417/ajaxsubmit/1/ajaxtype/normal' \
  $common_header \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Accept: application/json, text/javascript, */*; q=0.01' \
  -H "Referer: $REFERER" \
  -H 'X-Requested-With: XMLHttpRequest' \
  -H 'Connection: keep-alive' \
  --data "groupid=&redirect="%"2Fspace"%"2Fhome"%"2Findex&content="%"23dog"%"23&fileFrom=15&fids=${fids}&frommodule=space&publish_pic=" \
  --compressed -s