如何共享联盟cookie
既然我们获取到了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的更多相关文章
- 黄聪:Wordpress二级域名共享用户cookie出现错误解决方案及WP的Cookie机制
在若干年以前,我刚开始折腾Wordpress没多久的时候,就自己摸索过 多个Wordpress网站共享一份数据表的实现方法 .这种看起来好像很高大上的类SSO功能,能够给用户在多个网站之间提供快速.无 ...
- [php-cookie] cookie 请求跨域,如何共享
cookie 请求跨域的问题, 假设我有两个域名,一个 m.example.com,另一个是 www.example.com . 那么我需要如何设置 cookie 才可以在这两个域名都实现共享呢? / ...
- cookie,Session机制的本质,跨应用程序的session共享
目录:一.术语session二.HTTP协议与状态保持三.理解cookie机制四.理解session机制五.理解javax.servlet.http.HttpSession六.HttpSession常 ...
- 跨域共享cookie和跨域共享session
转载自:http://blog.csdn.net/ahhsxy/article/details/7356128 这里所说的跨域,是指跨二级域名,而且这些域名对应的应用都在同一个app上, 比如我有以下 ...
- Javascript中关于cookie的那些事儿
Javascript-cookie 什么是cookie? 指某些网站为了辨别用户身份.进行session跟踪而储存在用户本地终端上的数据(通常经过加密).简单点来说就是:浏览器缓存. cookie由什 ...
- session & cookie(li)
Session & Cookie 一.定义 Session,用户在浏览某个网站时,从进入网站到浏览器关闭所经过的这段时间,也就是用户浏览这个网站所花费的时间.Cookie,由服务器端生成,发送 ...
- HTTP Session、Cookie机制详解
一.什么是http session,有什么用 HTTP协议本身是无状态的,本身并不能支持服务端保存客户端的状态信息,于是,Web Server中引入了session的概念,用来保存客户端的状态信息. ...
- ASP.NET Cookie(二)--控制Cookie的范围
默认情况下,一个站点的全部Cookie都一起存储在客户端上,而且所有Cookie都会随着对该站点发送的任何请求一起发送到服务器.也就是说,一个站点中的每个页面都能获得该站点的所有Cookie.但是,可 ...
- jsp 入门 cookie session
Java Server Page ==> 服务器端的动态页面资源.用来做显示的功能. JSP构成 ==> HTML 脚本代码 标签构成. JSP 原理 ==> 实际上就是 servl ...
随机推荐
- ZooKeeper Getting Started Guide
http://zookeeper.apache.org/doc/trunk/zookeeperStarted.html What is ZooKeeper? ZooKeeper is a centra ...
- 报错!!!Servlet.service() for servlet [action] in context with path [/myssh] threw exception [java.lang.NullPointerException] with root cause java.lang.NullPointerException
这个为什么报错啊~~ at com.hsp.basic.BasicService.executeQuery(BasicService.java:33) 这个对应的语句是 Query query = ...
- Mybatis_1(认识)一个简单的HelloWorld
1. 介绍: MyBatis是支持普通SQL查询,存储过程和高级映射的优秀持久层框架. MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索. MyBatis可以使用简单的XM ...
- Android常用的工具类SharedPreferences封装类SPUtils
package com.zhy.utils; import java.lang.reflect.InvocationTargetException; import java.lang.reflect. ...
- python语法_字典_字典操作
字典:使用映射关系来存储数据的 数据类型 dict = {''name“:"gm","age":"34"} 采用键值对来存储数据 key_v ...
- | 线段树-地平线horizon
[题目描述]:在地平线上有n个建筑物.每个建筑物在地平线上可以看成一个下边界和地平线重合的矩形.每个建筑物有三个描述(Li ,Ri,Hi),分别表示该建筑物的左边界,右边界,高度.输出输出这些建筑物在 ...
- PHP的运算符
1.算术运算符 2.赋值运算符 基本的赋值运算符是“=”. (1)引用赋值 PHP 支持引用赋值,使用“$var = &$othervar;”语法.引用赋值意味着两个变量指向了同一个数据,没有 ...
- PHP字符串处理 单引号 双引号 heredoc nowdoc 定界符
---恢复内容开始--- 2019年2月22日09:49:54 参考文档: http://php.net/manual/zh/language.types.string.php#language. ...
- js_初识js_js基本语法和数据类型
1.js基础 2.js.html.css运行在浏览器(客户端)的语言 java php运行在服务器端 js最初的目的:在客户端处理表单的验证操作 js的解释器被称为js引擎,为浏览器的一部分,最早是在 ...
- -ms、-moz、-webkit -o
-ms-transform:rotate(7deg); //-ms代表ie内核 识别码-moz-transform:rotate(7deg); //-moz代表火狐内核识别码 -webkit-tran ...