接上一篇阿里妈妈账号登录状态如何长时间保存

既然我们获取到了cookie, 如果有多个程序都要使用到联盟帐号的时候, 如果不共享cookie, 那么每个程序都需要登录一次, 真的很浪费资源.

如何共享呢, 那就是建立一个http的服务, 提供http的接口.

如代码所示:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, diocp.ex.httpServer, ExtCtrls, ShellAPI; type
TFrmMain = class(TForm)
Button1: TButton;
Edit1: TEdit;
mmo1: TMemo;
pnl1: TPanel;
btn1: TButton;
tmr1: TTimer;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btn1Click(Sender: TObject);
procedure tmr1Timer(Sender: TObject);
private
{ Private declarations }
FTcpServer: TDiocpHttpServer;
procedure OnHttpSvrRequest(pvRequest:TDiocpHttpRequest);
procedure StartLogin();
function AtractProcess(sExe: string): Boolean;
public
{ Public declarations }
end; var
FrmMain: TFrmMain; implementation
uses uFMMonitor, diocp.core.engine; {$R *.dfm}procedure TFrmMain.Button1Click(Sender: TObject);
var
MOduleHandle:THandle;
TmpWndHandle:THandle;
aa:PChar;
begin
TmpWndHandle:=;
aa:=PChar(Edit1.Text);
TmpWndHandle:=FindWindowA(nil,aa);
if not IsWindow(TmpWndHandle) then
begin
mmo1.Lines.Add('没有找到窗口');
Exit;
end;
if InstallHook(FindWindowA(nil,aa)) then
mmo1.Lines.Add('挂载成功')
end; procedure TFrmMain.FormDestroy(Sender: TObject);
begin
UnHook;
end; procedure TFrmMain.OnHttpSvrRequest(pvRequest: TDiocpHttpRequest);
var
FLoad: TStringList;
begin
try
pvRequest.Response.ContentType := 'text/html; charset=utf-8';
pvRequest.DecodePostDataParam(false);
pvRequest.DecodeURLParam(false);
if pvRequest.RequestURI = '/GetCookie' then
begin
FLoad := TStringList.Create;
if FileExists(ExtractFilePath(ParamStr())+'cook.txt') then
FLoad.LoadFromFile(ExtractFilePath(ParamStr())+'cook.txt');
pvRequest.Response.WriteString(FLoad.Text);
FreeAndNil(FLoad);
end else
pvRequest.Response.WriteString('未知命令');
finally
pvRequest.ResponseEnd;
pvRequest.CloseContext;
end;
end; procedure TFrmMain.FormCreate(Sender: TObject);
begin
FTcpServer := TDiocpHttpServer.Create(Self);
FTcpServer.Name := 'HttpSVR';
FTcpServer.SetMaxSendingQueueSize();
FTcpServer.createDataMonitor;
FTcpServer.OnDiocpHttpRequest := OnHttpSvrRequest;
TFMMonitor.createAsChild(pnl1, FTcpServer);
FTcpServer.Port := ;
FTcpServer.Active := True;
end; procedure TFrmMain.StartLogin;
var
scmd, sPath: string;
begin
sCmd := '-lt 1 -ac -ap -dc -dp -pn AL6362845535841316741047753041';
sPath := ExtractFilePath(ParamStr());
ShellExecute(, 'open', PChar(sPath+'AliLogin.exe'), PChar(sCmd), nil, SW_SHOWNORMAL); tmr1.Enabled := True;
end; procedure TFrmMain.btn1Click(Sender: TObject);
begin
StartLogin();
end; function TFrmMain.AtractProcess(sExe: string): Boolean;
var
MOduleHandle:THandle;
TmpWndHandle:THandle;
aa:PChar;
begin
Result := False;
TmpWndHandle:=;
aa:=PChar(sExe);
TmpWndHandle:=FindWindowA(nil,aa);
if not IsWindow(TmpWndHandle) then
begin
mmo1.Lines.Add('没有找到窗口');
Exit;
end;
if InstallHook(FindWindowA(nil,aa)) then
begin
mmo1.Lines.Add('挂载成功');
Result := True;
end;
end; procedure TFrmMain.tmr1Timer(Sender: TObject);
begin
if AtractProcess('阿里妈妈登录窗体') then
tmr1.Enabled := False;
end; end.

我们把注入获取的cookie保存在cook.txt文件中, 当服务器开启后, 调用接口 http://服务器IP:9091/GetCookie?

在这个http服务中, 使用的是开源的diocp, 使用起来很简单.

下节预告  如何获取单品优惠券

如何共享联盟cookie的更多相关文章

  1. 黄聪:Wordpress二级域名共享用户cookie出现错误解决方案及WP的Cookie机制

    在若干年以前,我刚开始折腾Wordpress没多久的时候,就自己摸索过 多个Wordpress网站共享一份数据表的实现方法 .这种看起来好像很高大上的类SSO功能,能够给用户在多个网站之间提供快速.无 ...

  2. [php-cookie] cookie 请求跨域,如何共享

    cookie 请求跨域的问题, 假设我有两个域名,一个 m.example.com,另一个是 www.example.com . 那么我需要如何设置 cookie 才可以在这两个域名都实现共享呢? / ...

  3. cookie,Session机制的本质,跨应用程序的session共享

    目录:一.术语session二.HTTP协议与状态保持三.理解cookie机制四.理解session机制五.理解javax.servlet.http.HttpSession六.HttpSession常 ...

  4. 跨域共享cookie和跨域共享session

    转载自:http://blog.csdn.net/ahhsxy/article/details/7356128 这里所说的跨域,是指跨二级域名,而且这些域名对应的应用都在同一个app上, 比如我有以下 ...

  5. Javascript中关于cookie的那些事儿

    Javascript-cookie 什么是cookie? 指某些网站为了辨别用户身份.进行session跟踪而储存在用户本地终端上的数据(通常经过加密).简单点来说就是:浏览器缓存. cookie由什 ...

  6. session & cookie(li)

    Session & Cookie 一.定义 Session,用户在浏览某个网站时,从进入网站到浏览器关闭所经过的这段时间,也就是用户浏览这个网站所花费的时间.Cookie,由服务器端生成,发送 ...

  7. HTTP Session、Cookie机制详解

    一.什么是http session,有什么用 HTTP协议本身是无状态的,本身并不能支持服务端保存客户端的状态信息,于是,Web Server中引入了session的概念,用来保存客户端的状态信息. ...

  8. ASP.NET Cookie(二)--控制Cookie的范围

    默认情况下,一个站点的全部Cookie都一起存储在客户端上,而且所有Cookie都会随着对该站点发送的任何请求一起发送到服务器.也就是说,一个站点中的每个页面都能获得该站点的所有Cookie.但是,可 ...

  9. jsp 入门 cookie session

    Java Server Page ==> 服务器端的动态页面资源.用来做显示的功能. JSP构成 ==> HTML 脚本代码 标签构成. JSP 原理 ==> 实际上就是 servl ...

随机推荐

  1. django——url(路由)配置

    URL是Web服务的入口,用户通过浏览器发送过来的任何请求,都是发送到一个指定的URL地址,然后被响应. 在Django项目中编写路由,就是向外暴露我们接收哪些URL的请求,除此之外的任何URL都不被 ...

  2. Android应用程序MVC框架实例分析

    问题提出:如何优雅地分离出应用程序的状态.用户交互和数据表现?如何通过框架体现工程的高性能.高灵活性.高响应性? MVC定义:model.view.controller三者的有机组合,分别表示:模型. ...

  3. Node.js_ express.Router 路由器_模块化管理路由

    路由器 express.Router 路由器 模块化管理 路由 基本使用: 路由模块 1. 引入 express const express = require('express'); 其他相关模块 ...

  4. 目录的rwx权限的意义

    1.目录的r:列举查看目录下的内容 2.目录的w:向目录中写东西,如创建文件 3.目录的x:可以cd进去 例:查看/etc/passwd内容: `:对/有rx权限 `:对/etc/有rx权限 `:对/ ...

  5. python获取文件所在目录

    1.执行的python程序获取自己文件所在目录 import os,sys os.chdir(sys.path[0]); dir_name = os.path.abspath(os.path.join ...

  6. snmp简单测试

    一.环境搭建 搜索windows Server2003安装配置snmp 服务,按照提示来就行 二.利用 1.找出Coummunity Strings 利用于 auxiliary/scanner/snm ...

  7. CodeForces 1143A The Doors

    The Doors 签到题 #include <iostream> using namespace std; int a[200005]; int main() { int n; scan ...

  8. RxSwift + Moya + ObjectMapper

    https://www.jianshu.com/p/173915b943af use_frameworks! target 'RXDemo' do pod 'RxSwift' pod 'RxCocoa ...

  9. odoo按钮触发下载文件

    测试环境:Odoo8.0 1.在你的模块中创建一个方法,返回url 举个例子, @api.multi def get_stock_file(self): return{'type':'ir.actio ...

  10. spark核心优化详解

    大家好!转眼又到了经验分享的时间了.吼吼,我这里没有摘要也没有引言,只有单纯的经验分享,请见谅哦! 言归正传,目前在大数据领域能够提供的核心计算的工具,如离线计算hadoop生态圈的mr计算模型,以及 ...