Thiên Chi Kiều Nữ 537 Posted December 25, 2020 7 hours ago, Công Dũng said: em thử cũng không được. em tìm hiểu mà cũng k biết Shopee nó chặn theo tiêu chí gì luôn bạn request cái gì trên trang shopee thế ?? và bao lâu thì bị ??? mỵ thử xem nào =.='' đã thay ip vs useragent rồi mà vẫn bị thì hơi vô lý :v .. 1 Quote Share this post Link to post Share on other sites
Công Dũng 3 Posted January 5 On 25/12/2020 at 15:28, Thiên Chi Kiều Nữ said: bạn request cái gì trên trang shopee thế ?? và bao lâu thì bị ??? mỵ thử xem nào =.='' đã thay ip vs useragent rồi mà vẫn bị thì hơi vô lý :v .. em làm được rồi nha mỵ cảm ơn mỵ đã tư vấn nhiệt tình kk Quote Share this post Link to post Share on other sites
QuangBlue 1 Posted January 6 On 3/22/2019 at 3:49 PM, Huân Hoàng said: 3/ Chat với Shop: Chat shopee dựa trên WebSocket thì _HttpRequest đã hỗ trợ tương tác WebSocket trên Win10 (Win8 trở xuống WinHttp không hỗ trợ WebSocket) Code như thế này: Hidden Content Local $aInfo = Shopee_Login($Username, $Password) $from_userid = '118420826' $to_userid = '61130130' $ShopID = '61128688' $itemid = '1305829881' $Text = 'Test chat thử này ' & Random(0, 1) _HttpRequest(2, 'wss://chat-ws.shopee.vn/socket.io/?EIO=3&transport=websocket') _HttpRequest_WebSocketSend('42["message","13{\"token\":\"ABC\",\"country\":\"VN\"}"]') _HttpRequest_WebSocketSend('42["message","59{\"text_content\":\"{\\\"text\\\":\\\"' & $Text & '\\\"}\",\"to_userid\":' & $to_userid & ',\"from_userid\":' & $from_userid & ',\"itemid\":' & $itemid & ',\"orderid\":0,\"shopid\":' & $ShopID & ',\"type\":0,\"opt\":8,\"read\":true,\"requestid\":\"ABC\"}"]') Trong đó $from_userid, $to_userid , $ShopID, $itemid dễ dàng tìm được nên iêm sẽ không code cụ thể nữa, ai thích tìm hiểu thì tự code nhoé ($from_userid thì lấy từ kết quả trả về của hàm Shoppe_Login. $to_userid , $ShopID thì từ kết quả hàm Shopee_ShopInfo ...) Demo: https://www.youtube.com/watch?v=p2zby2DEw1g Vậy là iêm đã lướt qua một số request cơ bản tương tác với Shopee, chúc các thým tìm hiểu vui vẻ và thích thú với nhánh HTTP Request này Có bác nào chuyển đoạn code này sang python đc không ạ :D. Em tay ngang đọc không hiểu được huhu Quote Share this post Link to post Share on other sites
Thiên Chi Kiều Nữ 537 Posted January 6 15 hours ago, QuangBlue said: Có bác nào chuyển đoạn code này sang python đc không ạ :D. Em tay ngang đọc không hiểu được huhu mỵ ko còn thấy shopee xài websocket nữa rồi bạn...giờ chat sang api rồi ..bạn thử đi ... nếu bạn tìm thấy link nào shopee sử dụng websocket thì up lên cho mỵ xem với... Quote Share this post Link to post Share on other sites
QuangBlue 1 Posted January 7 On 1/7/2021 at 2:31 AM, Thiên Chi Kiều Nữ said: mỵ ko còn thấy shopee xài websocket nữa rồi bạn...giờ chat sang api rồi ..bạn thử đi ... nếu bạn tìm thấy link nào shopee sử dụng websocket thì up lên cho mỵ xem với... Vậy Mỵ hướng dẫn mình cái request api dc ko ? Mò hoài vẫn ko dc :( -------------------------------------------------------------------- Ghép bài -------------------------------------------------------------------- On 1/7/2021 at 2:31 AM, Thiên Chi Kiều Nữ said: mỵ ko còn thấy shopee xài websocket nữa rồi bạn...giờ chat sang api rồi ..bạn thử đi ... nếu bạn tìm thấy link nào shopee sử dụng websocket thì up lên cho mỵ xem với... { "data": null, "error_code": "", "message": "" } luôn bị lỗi 426 upgrade required :( Quote Share this post Link to post Share on other sites
Thiên Chi Kiều Nữ 537 Posted January 8 8 hours ago, QuangBlue said: Vậy Mỵ hướng dẫn mình cái request api dc ko ? Mò hoài vẫn ko dc :( -------------------------------------------------------------------- Ghép bài -------------------------------------------------------------------- { "data": null, "error_code": "", "message": "" } luôn bị lỗi 426 upgrade required :( Bình thường mà bạn.... cố lên tí nữa đi Quote Share this post Link to post Share on other sites
QuangBlue 1 Posted January 8 3 hours ago, Thiên Chi Kiều Nữ said: Bình thường mà bạn.... cố lên tí nữa đi Mỵ share code nay cho Mình được ko :( Quote Share this post Link to post Share on other sites
Thiên Chi Kiều Nữ 537 Posted January 8 1 hour ago, QuangBlue said: Mỵ share code nay cho Mình được ko :( Bạn gửi code lỗi của bạn rồi mỵ hướng dẫn fix ... chứ mỵ ko đăng code được Quote Share this post Link to post Share on other sites
QuangBlue 1 Posted January 8 20 hours ago, Thiên Chi Kiều Nữ said: Bạn gửi code lỗi của bạn rồi mỵ hướng dẫn fix ... chứ mỵ ko đăng code được import requests, json, hashlib, random def encrypt_SHA256(password): sha_signature = \ hashlib.sha256((hashlib.md5(password.encode()).hexdigest()).encode()).hexdigest() return sha_signature def csrf_token(): character='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' return ''.join((random.choice(character) for i in range(22))) + '%3D%3D' def csrftoken(length=32): character='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' return ''.join((random.choice(character) for i in range(8))) + '-' + ''.join((random.choice(character) for i in range(4))) + '-' + ''.join((random.choice(character) for i in range(4))) + '-' + ''.join((random.choice(character) for i in range(4))) + '-' + ''.join((random.choice(character) for i in range(12))) def sign_in_shopee(): q = csrftoken() id_sp = "xxxxxxx" pass_sh = encrypt_SHA256("xxxxxxx") session = requests.Session() payload = { 'phone' : id_sp, 'password_hash': pass_sh, 'remember': 'false', } url='https://banhang.shopee.vn/api/v2/login/?SPC_CDS=' + q + '&SPC_CDS_VER=2' response = session.request("POST",url, data = payload) if response.status_code != 200 : print (f'Đăng nhập thất bại tài khoản {id_sp}. Lỗi ' + str(response.status_code)) exit() return response.cookies def get_auth(cookies): url = 'https://banhang.shopee.vn/webchat/api/v1.2/mini/login?source=sc&_v=4.8.0&_api_source=sc' request_post = requests.post(url,cookies=cookies) results = request_post.json() return results def new_cookie(coo,csrf_token): g = requests.cookies.RequestsCookieJar() g.set(domain='.shopee.vn',name='CTOKEN',value=csrf_token) coo.update(g) x = coo return x def new_ctoken(auth_code,csrf_token,new_cookie,uid): headers ={ 'authorization' : f'Bearer {auth_code}' } cookies = new_cookie url = f'https://banhang.shopee.vn/webchat/api/v1.2/login?_uid={uid}&csrf_token={csrf_token}' x = requests.post(url,headers=headers,cookies=cookies) k = dict(x.cookies.iteritems()) k['token'] = x.json()['token'] return k def chat(uid,csrf_token_30,new_auth,coo): url = f'https://banhang.shopee.vn/webchat/api/v1.2/messages?_uid={uid}&csrf_token={csrf_token_30}' headers = { 'accept' : '*/*', 'accept-encoding' : 'gzip, deflate, br', 'authorization' : f'Bearer {new_auth}', 'content-type' : 'text/plain;charset=UTF-8', 'referer' : 'https://banhang.shopee.vn/webchat/conversations', 'pragma' : 'no-cache', 'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66' } g = requests.cookies.RequestsCookieJar() g.set(domain='.shopee.vn',name='CTOKEN',value=csrf_token_30) coo.update(g) cookies = coo data = { "request_id":"23423427", "to_id":230448022, "type":"text", "content":{"text":"Dạ cảm ơn bạn rất nhiều nè"}, "chat_send_option":{"force_send_cancel_order_warning":False,"comply_cancel_order_warning":False}} i = requests.post(url, headers=headers, cookies=cookies, data=data) if __name__ == "__main__": cookies = sign_in_shopee() auth_code = get_auth(cookies)['token'] csrf_token = csrf_token() new_cookie = new_cookie(cookies,csrf_token) uid = get_auth(cookies)['user']['uid'] csrf_token_30 = new_ctoken(auth_code,csrf_token,new_cookie,uid)['CTOKEN'] new_auth = new_ctoken(auth_code,csrf_token,new_cookie,uid)['token'] chat(uid,csrf_token_30,new_auth,cookies) Mình tay ngang nên code hơi bẩn tý T_T Quote Share this post Link to post Share on other sites
Thiên Chi Kiều Nữ 537 Posted January 9 16 hours ago, QuangBlue said: import requests, json, hashlib, random def encrypt_SHA256(password): sha_signature = \ hashlib.sha256((hashlib.md5(password.encode()).hexdigest()).encode()).hexdigest() return sha_signature def csrf_token(): character='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' return ''.join((random.choice(character) for i in range(22))) + '%3D%3D' def csrftoken(length=32): character='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' return ''.join((random.choice(character) for i in range(8))) + '-' + ''.join((random.choice(character) for i in range(4))) + '-' + ''.join((random.choice(character) for i in range(4))) + '-' + ''.join((random.choice(character) for i in range(4))) + '-' + ''.join((random.choice(character) for i in range(12))) def sign_in_shopee(): q = csrftoken() id_sp = "xxxxxxx" pass_sh = encrypt_SHA256("xxxxxxx") session = requests.Session() payload = { 'phone' : id_sp, 'password_hash': pass_sh, 'remember': 'false', } url='https://banhang.shopee.vn/api/v2/login/?SPC_CDS=' + q + '&SPC_CDS_VER=2' response = session.request("POST",url, data = payload) if response.status_code != 200 : print (f'Đăng nhập thất bại tài khoản {id_sp}. Lỗi ' + str(response.status_code)) exit() return response.cookies def get_auth(cookies): url = 'https://banhang.shopee.vn/webchat/api/v1.2/mini/login?source=sc&_v=4.8.0&_api_source=sc' request_post = requests.post(url,cookies=cookies) results = request_post.json() return results def new_cookie(coo,csrf_token): g = requests.cookies.RequestsCookieJar() g.set(domain='.shopee.vn',name='CTOKEN',value=csrf_token) coo.update(g) x = coo return x def new_ctoken(auth_code,csrf_token,new_cookie,uid): headers ={ 'authorization' : f'Bearer {auth_code}' } cookies = new_cookie url = f'https://banhang.shopee.vn/webchat/api/v1.2/login?_uid={uid}&csrf_token={csrf_token}' x = requests.post(url,headers=headers,cookies=cookies) k = dict(x.cookies.iteritems()) k['token'] = x.json()['token'] return k def chat(uid,csrf_token_30,new_auth,coo): url = f'https://banhang.shopee.vn/webchat/api/v1.2/messages?_uid={uid}&csrf_token={csrf_token_30}' headers = { 'accept' : '*/*', 'accept-encoding' : 'gzip, deflate, br', 'authorization' : f'Bearer {new_auth}', 'content-type' : 'text/plain;charset=UTF-8', 'referer' : 'https://banhang.shopee.vn/webchat/conversations', 'pragma' : 'no-cache', 'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66' } g = requests.cookies.RequestsCookieJar() g.set(domain='.shopee.vn',name='CTOKEN',value=csrf_token_30) coo.update(g) cookies = coo data = { "request_id":"23423427", "to_id":230448022, "type":"text", "content":{"text":"Dạ cảm ơn bạn rất nhiều nè"}, "chat_send_option":{"force_send_cancel_order_warning":False,"comply_cancel_order_warning":False}} i = requests.post(url, headers=headers, cookies=cookies, data=data) if __name__ == "__main__": cookies = sign_in_shopee() auth_code = get_auth(cookies)['token'] csrf_token = csrf_token() new_cookie = new_cookie(cookies,csrf_token) uid = get_auth(cookies)['user']['uid'] csrf_token_30 = new_ctoken(auth_code,csrf_token,new_cookie,uid)['CTOKEN'] new_auth = new_ctoken(auth_code,csrf_token,new_cookie,uid)['token'] chat(uid,csrf_token_30,new_auth,cookies) Mình tay ngang nên code hơi bẩn tý T_T Hự...bạn nạp cookie tạm rồi gửi mỵ đoạn request chát thôi đọc rồi quá hihi....chả có hàng lối gì cả... @QuangBlue à mỵ quên mất, bạn còn phải tìm giá trị authorization là đoạn Bearer eyJ............... để thêm vào header nữa mới chạy được nhé. Quote Share this post Link to post Share on other sites
QuangBlue 1 Posted January 9 10 hours ago, Thiên Chi Kiều Nữ said: Hự...bạn nạp cookie tạm rồi gửi mỵ đoạn request chát thôi đọc rồi quá hihi....chả có hàng lối gì cả... @QuangBlue à mỵ quên mất, bạn còn phải tìm giá trị authorization là đoạn Bearer eyJ............... để thêm vào header nữa mới chạy được nhé. def chat(uid,csrf_token_30,new_auth,coo): url = f'https://banhang.shopee.vn/webchat/api/v1.2/messages?_uid={uid}&csrf_token={csrf_token_30}' # ĐOẠN NÀY 'authorization' LẤY TỪ REQUEST TỚI URL LOGIN headers = { 'accept' : '*/*', 'accept-encoding' : 'gzip, deflate, br', 'authorization' : f'Bearer {new_auth}', # ĐOẠN MỴ NÓI NÈ PHẢI KO ? 'content-type' : 'text/plain;charset=UTF-8', 'referer' : 'https://banhang.shopee.vn/webchat/conversations', 'pragma' : 'no-cache', 'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66' } # ĐOẠN NÀY LÀ ADD THÊM CÁI CTONKEN VÀO COOKIE g = requests.cookies.RequestsCookieJar() g.set(domain='.shopee.vn',name='CTOKEN',value=csrf_token_30) coo.update(g) cookies = coo # ĐOẠN NÀY LÀ DATA PAYLOAD data = { "request_id":"23423427", "to_id":230448022, "type":"text", "content":{"text":"Dạ cảm ơn bạn rất nhiều nè"}, "chat_send_option":{"force_send_cancel_order_warning":False,"comply_cancel_order_warning":False}} i = requests.post(url, headers=headers, cookies=cookies, data=data) Quote Share this post Link to post Share on other sites
Thiên Chi Kiều Nữ 537 Posted January 11 On 1/10/2021 at 1:21 AM, QuangBlue said: def chat(uid,csrf_token_30,new_auth,coo): url = f'https://banhang.shopee.vn/webchat/api/v1.2/messages?_uid={uid}&csrf_token={csrf_token_30}' # ĐOẠN NÀY 'authorization' LẤY TỪ REQUEST TỚI URL LOGIN headers = { 'accept' : '*/*', 'accept-encoding' : 'gzip, deflate, br', 'authorization' : f'Bearer {new_auth}', # ĐOẠN MỴ NÓI NÈ PHẢI KO ? 'content-type' : 'text/plain;charset=UTF-8', 'referer' : 'https://banhang.shopee.vn/webchat/conversations', 'pragma' : 'no-cache', 'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66' } # ĐOẠN NÀY LÀ ADD THÊM CÁI CTONKEN VÀO COOKIE g = requests.cookies.RequestsCookieJar() g.set(domain='.shopee.vn',name='CTOKEN',value=csrf_token_30) coo.update(g) cookies = coo # ĐOẠN NÀY LÀ DATA PAYLOAD data = { "request_id":"23423427", "to_id":230448022, "type":"text", "content":{"text":"Dạ cảm ơn bạn rất nhiều nè"}, "chat_send_option":{"force_send_cancel_order_warning":False,"comply_cancel_order_warning":False}} i = requests.post(url, headers=headers, cookies=cookies, data=data) đúng rồi đấy bạn ... nhưng hình như cái token vs cái author nó lấy ở đâu vê ấy Quote Share this post Link to post Share on other sites
QuangBlue 1 Posted January 11 (edited) 10 hours ago, Thiên Chi Kiều Nữ said: đúng rồi đấy bạn ... nhưng hình như cái token vs cái author nó lấy ở đâu vê ấy Lấy từ https://banhang.shopee.vn/webchat/api/v1.2/login?_uid={uid}&csrf_token={csrf_token}' Mỵ xem giúp với, hix bí cả tuần ko làm được gì T_T Edited January 11 by QuangBlue Quote Share this post Link to post Share on other sites