Delphi7微信、支付宝扫码支付源码_Delphi7微信支付

unit declaredll;

interface
function WeiXinQueryEx1(inappid:Pchar;inmchid:Pchar;inIdkey:Pchar;IdkeyLock:Integer;inNum:Pchar;var ReturnXmlInf:Pchar):integer;stdcall external 'PayApiFun.dll';
function WeiXinPayQRCodeEx1(inappid:Pchar;inmchid:Pchar;inIdkey:Pchar;IdkeyLock:Integer;inNum:Pchar; inTotalFee:Pchar;inbody:Pchar;var ReturnXmlInf:Pchar):integer;stdcall external 'PayApiFun.dll';
function WeiXinPayCodeEx1(inappid:Pchar;inmchid:Pchar;inIdkey:Pchar;IdkeyLock:Integer;inAuthCode:Pchar ;inNum:Pchar; inTotalFee:Pchar;inbody:Pchar;var ReturnXmlInf:Pchar):integer;stdcall external 'PayApiFun.dll';
function WeiXinCloseOrderEx1(inappid:Pchar;inmchid:Pchar;inIdkey:Pchar;KeyLOck:Integer;inNum:Pchar;var ReturnXmlInf:Pchar):integer;stdcall external 'PayApiFun.dll';

function WeiXinQueryEx2(inappid:Pchar;inmchid:Pchar;registered:Integer;inIdkey:Pchar;IdkeyLock:Integer;inNum:Pchar;var ReturnXmlInf:Pchar):integer;stdcall external 'PayApiFun.dll';
function WeiXinPayQRCodeEx2(inappid:Pchar;inmchid:Pchar;registered:Integer;inIdkey:Pchar;IdkeyLock:Integer;inNum:Pchar; inTotalFee:Pchar;inbody:Pchar;var ReturnXmlInf:Pchar):integer;stdcall external 'PayApiFun.dll';
function WeiXinPayCodeEx2(inappid:Pchar;inmchid:Pchar;registered:Integer;inIdkey:Pchar;IdkeyLock:Integer;inAuthCode:Pchar ;inNum:Pchar; inTotalFee:Pchar;inbody:Pchar;var ReturnXmlInf:Pchar):integer;stdcall external 'PayApiFun.dll';
function WeiXinCloseOrderEx2(inappid:Pchar;inmchid:Pchar;registered:Integer;inIdkey:Pchar;IdkeyLock:Integer;inNum:Pchar;var ReturnXmlInf:Pchar):integer;stdcall external 'PayApiFun.dll';

function ZhiFuBaoPayCodeEx1(inappid:Pchar;inAuthCode:Pchar ;inNum:Pchar; inTotalFee:Pchar;inbody:Pchar;var ReturnXmlInf:Pchar):integer;stdcall external 'PayApiFun.dll';
function ZhiFuBaoPayQRCodeEx1(inappid:Pchar;inNum:Pchar;inTotalFee:Pchar;inbody:Pchar;var ReturnXmlInf:Pchar):integer;stdcall external 'PayApiFun.dll';
function ZhiFuBaoQueryEx1(inappid:Pchar;inNum:Pchar;var ReturnXmlInf:Pchar):integer;stdcall external 'PayApiFun.dll';
function ZhiFuBaoPayCancelEx1(inappid:Pchar;inNum:Pchar;var ReturnXmlInf:Pchar):integer;stdcall external 'PayApiFun.dll';

function ZhiFuBaoPayCodeEx2(inappid:Pchar;registered:Integer;inAuthCode:Pchar ;inNum:Pchar; inTotalFee:Pchar;inbody:Pchar;var ReturnXmlInf:Pchar):integer;stdcall external 'PayApiFun.dll';
function ZhiFuBaoPayQRCodeEx2(inappid:Pchar;registered:Integer;inNum:Pchar;inTotalFee:Pchar;inbody:Pchar;var ReturnXmlInf:Pchar):integer;stdcall external 'PayApiFun.dll';
function ZhiFuBaoQueryEx2(inappid:Pchar;registered:Integer;inNum:Pchar;var ReturnXmlInf:Pchar):integer;stdcall external 'PayApiFun.dll';
function ZhiFuBaoPayCancelEx2(inappid:Pchar;registered:Integer;inNum:Pchar;var ReturnXmlInf:Pchar):integer;stdcall external 'PayApiFun.dll';


function PQRCodeEx1(inpustr:PChar):integer;stdcall external 'PayApiFun.dll';
implementation

end.

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,declaredll,
Dialogs, StdCtrls, ExtCtrls, Buttons;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Memo1: TMemo;
Image1: TImage;
Edit1: TEdit;
Label1: TLabel;
Edit2: TEdit;
Edit3: TEdit;
Button7: TButton;
Label2: TLabel;
Label3: TLabel;
Edit4: TEdit;
Button8: TButton;
Label10: TLabel;
Label11: TLabel;
Edit5: TEdit;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
Memo2: TMemo;
Panel1: TPanel;
Image2: TImage;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
zfbappid: TEdit;
wxappid: TEdit;
wxmchid: TEdit;
wxidkey: TEdit;
BitBtn1: TBitBtn;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
Panel2: TPanel;
RadioButton3: TRadioButton;
RadioButton4: TRadioButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Edit1DblClick(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
inappid,inmchid,inIdkey,inNum:pchar;
real,registered,idkeylock:integer;
ReturnInf:pchar;//返回信息
errstr:string;
begin
inappid:=Pchar(trim(wxappid.Text)); //微信公众号
inmchid:=Pchar(trim(wxmchid.Text)); //商户号
if RadioButton4.Checked =true then registered:=1 else registered:=0; //1 公众号、商户号已加密授权 0 未加密授权

inIdkey:=Pchar(trim(wxidkey.Text)); //API密钥
if RadioButton2.Checked =true then idkeylock:=1 else idkeylock:=0; //1 API密钥,0未加密

inNum:=Pchar(trim(edit1.text));
ReturnInf := StrAlloc(255);

try
memo1.Lines.Clear ;
edit4.Text:='';

//real:=WeiXinQueryEx1(inappid,inmchid,inIdkey,idkeylock,inNum,ReturnInf); //第一代函数
real:=WeiXinQueryEx2(inappid,inmchid,registered,inIdkey,idkeylock,inNum,ReturnInf); //第二代函数

case real of
0:
begin
memo1.Lines.Add('微信支付单号:' + trim(edit1.text) + '支付成功!API接口返回的信息:' +PAnsiChar(string(ReturnInf)));
end;
1:
begin
memo1.Lines.Add('微信支付单号:' + trim(edit1.text) + '正在支付中,请稍后查询此单支付状态,API接口返回的信息:' +PAnsiChar(string(ReturnInf)));
end;
else
begin
memo1.Lines.Add('微信支付单号:' + trim(edit1.text) + '’支付失败!API接口返回的信息:' +PAnsiChar(string(ReturnInf)));
end;
end;
except
on E: Exception do
begin
Application.MessageBox(Pchar('微信API接口申请操作失败:'+E.Message), '警告', MB_OK+MB_ICONSTOP);
end;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
inappid,inmchid,inIdkey,inNum,inTotalFee,inbody:pchar;
real,registered,idkeylock:integer;
ReturnInf:pchar;//返回信息
begin
inappid:=Pchar(trim(wxappid.Text)); //微信公众号
inmchid:=Pchar(trim(wxmchid.Text)); //商户号
if RadioButton4.Checked =true then registered:=1 else registered:=0; //1 公众号、商户号已加密授权 0 未加密授权

inIdkey:=Pchar(trim(wxidkey.Text)); //API密钥
if RadioButton2.Checked =true then idkeylock:=1 else idkeylock:=0; //1 API密钥,0未加密

inNum:=Pchar(trim(edit1.text));
inTotalFee:=Pchar(trim(edit2.text));
inbody:=Pchar(trim(edit5.text));
ReturnInf := StrAlloc(255);

memo1.Lines.Clear ;
edit4.Text:='';

try
//real:=WeiXinPayQRCodeEx1(inappid,inmchid,inIdkey,idkeylock,inNum,inTotalFee,inbody,ReturnInf); //第一代函数
real:=WeiXinPayQRCodeEx2(inappid,inmchid,registered,inIdkey,idkeylock,inNum,inTotalFee,inbody,ReturnInf); //第二代函数调用

case real of
0:
begin
memo1.Lines.Add('微信支付单号:' + trim(edit1.text) + '支付二维码已经生成,有效时间5分钟,可轮询调用 查询微信订单状态 函数查询支付结果 或调用 关闭微信扫码订单。');
edit4.Text:=(PAnsiChar(string(ReturnInf)));
image1.Picture.LoadFromFile((PAnsiChar(ExtractFilePath(Application.Exename)+'QRcode.BMP')));
end;
1:
begin
memo1.Lines.Add('微信支付单号:' + trim(edit1.text) + '正在申请支付二维码...'+PAnsiChar(string(ReturnInf)));
end;
-10:
begin
memo1.Lines.Add('微信支付单号:' + trim(edit1.text) + '支付二维码已经返回,生成二维码图片时出现异常!');
edit4.Text:=(PAnsiChar(string(ReturnInf)));
end;
else
begin
memo1.Lines.Add('微信支付单号:' + trim(edit1.text) + '二维支付地址申请失败!'+PAnsiChar(string(ReturnInf)));
end;
end;
except
on E: Exception do
begin
Application.MessageBox(Pchar('微信API接口申请操作失败:'+E.Message), '警告', MB_OK+MB_ICONSTOP);
end;
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
inappid,inmchid,inIdkey,inAuthCode,inNum,inTotalFee,inbody:pchar;
real,registered,idkeylock:integer;
ReturnInf:pchar;//返回信息
begin
if trim(edit3.text)='' then
begin
Application.MessageBox(Pchar('请输入正确的微信付款码!'), '警告', MB_OK+MB_ICONSTOP);
edit3.SetFocus;
exit;
end;

inappid:=Pchar(trim(wxappid.Text)); //微信公众号
inmchid:=Pchar(trim(wxmchid.Text)); //商户号
if RadioButton4.Checked =true then registered:=1 else registered:=0; //1 公众号、商户号已加密授权 0 未加密授权

inIdkey:=Pchar(trim(wxidkey.Text)); //API密钥
if RadioButton2.Checked =true then idkeylock:=1 else idkeylock:=0; //1 API密钥,0未加密

inNum:=Pchar(trim(edit1.text));
inTotalFee:=Pchar(trim(edit2.text));
inAuthCode:=Pchar(trim(edit3.text));
inbody:=Pchar(trim(edit5.text));
ReturnInf := StrAlloc(255);

memo1.Lines.Clear ;
edit4.Text:='';

try
//real:=WeiXinPayCodeEx1(inappid,inmchid,inIdkey,idkeylock,inAuthCode,inNum,inTotalFee,inbody,ReturnInf); //第一代函数
real:=WeiXinPayCodeEx2(inappid,inmchid,registered,inIdkey,idkeylock,inAuthCode,inNum,inTotalFee,inbody,ReturnInf); //第二代函数,

case real of
0:
begin
memo1.Lines.Add('微信支付单号:' + trim(edit1.text) + '支付成功!API接口返回的信息:' +PAnsiChar(string(ReturnInf)));
end;
1:
begin
memo1.Lines.Add('微信支付单号:' + trim(edit1.text) + '正在支付中,请稍后查询此单支付状态,API接口返回的信息:' +PAnsiChar(string(ReturnInf)));
end;
else
begin
memo1.Lines.Add('微信支付单号:' + trim(edit1.text) + '’支付失败!API接口返回的信息:' +PAnsiChar(string(ReturnInf)));
end;
end;
except
on E: Exception do
begin
Application.MessageBox(Pchar('微信API接口申请操作失败:'+E.Message), '警告', MB_OK+MB_ICONSTOP);
end;
end;
end;

procedure TForm1.Button4Click(Sender: TObject);
var
inappid,inmchid,inIdkey,inNum,inTotalFee,inbody:pchar;
real,registered:integer;
usemon:Currency;
ReturnInf:pchar;//返回信息
begin
inappid:=Pchar(trim(zfbappid.text)); //支付宝APPID
if RadioButton4.Checked =true then registered:=1 else registered:=0; //1 支付宝APPID已加密授权 0 未加密授权

inNum:=Pchar(trim(edit1.text)); //商户订单编号
usemon:=strtoint64(edit2.text)/100;
inTotalFee:=Pchar(floattostr(usemon));
inbody:=Pchar(trim(edit5.text));
ReturnInf := StrAlloc(255);

memo1.Lines.Clear ;
edit4.Text:='';

try
//real:=ZhiFuBaoPayQRCodeEx1(inappid,inNum,inTotalFee,inbody,ReturnInf); //第一代函数
real:=ZhiFuBaoPayQRCodeEx2(inappid,registered,inNum,inTotalFee,inbody,ReturnInf); //第二代函数

case real of
0:
begin
memo1.Lines.Add('支付宝支付单号:' + trim(edit1.text) + '支付二维码已经生成,有效时间5分钟,可轮询调用 查询支付宝订单状态 函数查询支付结果 或 调用 撤销支付宝支付订单');
edit4.Text:=(PAnsiChar(string(ReturnInf)));
image1.Picture.LoadFromFile((PAnsiChar(ExtractFilePath(Application.Exename)+'QRcode.BMP')));
end;
else
begin
memo1.Lines.Add('支付宝支付单号:' + trim(edit1.text) + '二维支付地址申请失败!'+PAnsiChar(string(ReturnInf)));
end;
end;
except
on E: Exception do
begin
Application.MessageBox(Pchar('支付宝API接口申请操作失败:'+E.Message), '警告', MB_OK+MB_ICONSTOP);
end;
end;

end;

procedure TForm1.Button5Click(Sender: TObject);
var
inappid,inAuthCode,inNum,inTotalFee,inbody:pchar;
real,registered:integer;
usemon:Currency;
ReturnInf:pchar;//返回信息
begin
if trim(edit3.text)='' then
begin
Application.MessageBox(Pchar('请输入正确的支付宝付款码!'), '警告', MB_OK+MB_ICONSTOP);
edit3.SetFocus;
exit;
end;

inappid:=Pchar(trim(zfbappid.text)); //支付宝APPID
if RadioButton4.Checked =true then registered:=1 else registered:=0; //1 支付宝APPID已加密授权 0 未加密授权

inNum:=Pchar(trim(edit1.text)); //商户订单编号
usemon:=strtoint64(edit2.text)/100;
inTotalFee:=Pchar(floattostr(usemon));
ReturnInf := StrAlloc(255);
inAuthCode:=Pchar(trim(edit3.text));
inbody:=Pchar(trim(edit5.text));
ReturnInf := StrAlloc(255);

memo1.Lines.Clear ;
edit4.Text:='';
try
//real:=ZhiFuBaoPayCodeEx1(inappid,inAuthCode,inNum,inTotalFee,inbody,ReturnInf); //第一代函数
real:=ZhiFuBaoPayCodeEx2(inappid,registered,inAuthCode,inNum,inTotalFee,inbody,ReturnInf); //第二代函数

case real of
0:
begin
memo1.Lines.Add('支付宝支付单号:' + trim(edit1.text) + '支付成功!API接口返回的信息:' +PAnsiChar(string(ReturnInf)));
end;
1:
begin
memo1.Lines.Add('支付宝支付单号:' + trim(edit1.text) + '正在支付中,请稍后查询此单支付状态,API接口返回的信息:' +PAnsiChar(string(ReturnInf)));
end;
else
begin
memo1.Lines.Add('支付宝支付单号:' + trim(edit1.text) + '支付失败!API接口返回的信息:' +PAnsiChar(string(ReturnInf)));
end;
end;
except
on E: Exception do
begin
Application.MessageBox(Pchar('支付宝API接口申请操作失败:'+E.Message), '警告', MB_OK+MB_ICONSTOP);
end;
end;

end;

procedure TForm1.Button6Click(Sender: TObject);
var
inappid,inNum:pchar;
real,registered:integer;
ReturnInf:pchar;//返回信息
begin
inappid:=Pchar(trim(zfbappid.text)); //支付宝APPID
if RadioButton4.Checked =true then registered:=1 else registered:=0; //1 支付宝APPID已加密授权 0 未加密授权

inNum:=Pchar(trim(edit1.text)); //商户订单编号
ReturnInf := StrAlloc(255);

try
memo1.Lines.Clear ;
edit4.Text:='';

//real:=ZhiFuBaoQueryEx1(inappid,inNum,ReturnInf); //第一代函数
real:=ZhiFuBaoQueryEx2(inappid,registered,inNum,ReturnInf); //第二代函数

case real of
0:
begin
memo1.Lines.Add('支付宝订单号:' + trim(edit1.text) + '支付成功!API接口返回的信息:' +PAnsiChar(string(ReturnInf)));
end;
1:
begin
memo1.Lines.Add('支付宝订单号:' + trim(edit1.text) + '正在支付中,请稍后查询此单支付状态,API接口返回的信息:' +PAnsiChar(string(ReturnInf)));
end;
else
begin
memo1.Lines.Add('支付宝订单号:' + trim(edit1.text) + '’支付失败!API接口返回的信息:' +PAnsiChar(string(ReturnInf)));
end;
end;

except
on E: Exception do
begin
Application.MessageBox(Pchar('支付宝API接口申请操作失败:'+E.Message), '警告', MB_OK+MB_ICONSTOP);
end;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
edit1.Text :=FormatDateTime('yyyyMMddHHmmss',now)+'0001';
if FileExists(PAnsiChar(ExtractFilePath(Application.Exename)+'QRcode.BMP')) then
begin
image1.Picture.LoadFromFile((PAnsiChar(ExtractFilePath(Application.Exename)+'QRcode.BMP')));
end;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Panel1.Visible :=false;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
Panel1.Visible :=true;
end;

procedure TForm1.Button8Click(Sender: TObject);
var
real:integer;
begin
if edit4.Text ='' then
begin
Application.MessageBox(Pchar('请输入要生成二维码的字符信息!'), '警告', MB_OK+MB_ICONSTOP);
edit4.SetFocus ;
end
else
begin
real:=PQRCodeEx1(Pchar(trim(edit4.Text)));
if real=0 then image1.Picture.LoadFromFile((PAnsiChar(ExtractFilePath(Application.Exename)+'QRcode.BMP')));
end;
end;

procedure TForm1.Edit1DblClick(Sender: TObject);
begin
edit1.Text :=FormatDateTime('yyyyMMddHHmmss',now)+'0001';
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
var
inappid,inmchid,inIdkey,inNum:pchar;
real,registered,idkeylock:integer;
ReturnInf:pchar;//返回信息
errstr:string;
begin
inappid:=Pchar(trim(wxappid.Text)); //微信公众号
inmchid:=Pchar(trim(wxmchid.Text)); //商户号
if RadioButton4.Checked =true then registered:=1 else registered:=0; //1 公众号、商户号已加密授权 0 未加密授权

inIdkey:=Pchar(trim(wxidkey.Text)); //API密钥
if RadioButton2.Checked =true then idkeylock:=1 else idkeylock:=0; //1 API密钥,0未加密

inNum:=Pchar(trim(edit1.text));
ReturnInf := StrAlloc(255);

try
memo1.Lines.Clear ;
edit4.Text:='';

//real:=WeiXinCloseOrderEx1(inappid,inmchid,inIdkey,idkeylock,inNum,ReturnInf); //第一代函数
real:=WeiXinCloseOrderEx2(inappid,inmchid,registered,inIdkey,idkeylock,inNum,ReturnInf); //第二代函数

case real of
0:
begin
memo1.Lines.Add('微信支付单号:' + trim(edit1.text) + '关闭成功!API接口返回的信息:' +PAnsiChar(string(ReturnInf)));
end;
else
begin
memo1.Lines.Add('微信支付单号:' + trim(edit1.text) + '关闭失败!API接口返回的信息:' +PAnsiChar(string(ReturnInf)));
end;
end;
except
on E: Exception do
begin
Application.MessageBox(Pchar('微信API接口申请操作失败:'+E.Message), '警告', MB_OK+MB_ICONSTOP);
end;
end;
end;

procedure TForm1.BitBtn3Click(Sender: TObject);
var
inappid,inNum:pchar;
real,registered:integer;
ReturnInf:pchar;//返回信息
begin
inappid:=Pchar(trim(zfbappid.text)); //支付宝APPID
if RadioButton4.Checked =true then registered:=1 else registered:=0; //1 支付宝APPID已加密授权 0 未加密授权

inNum:=Pchar(trim(edit1.text)); //商户订单编号
ReturnInf := StrAlloc(255);

try
memo1.Lines.Clear ;
edit4.Text:='';

//real:=ZhiFuBaoPayCancelEx1(inappid,inNum,ReturnInf); //第一代函数
real:=ZhiFuBaoPayCancelEx2(inappid,registered,inNum,ReturnInf); //第二代函数

case real of
0:
begin
memo1.Lines.Add('支付宝支付单号:' + trim(edit1.text) + '还未支付,已撒销成功!API接口返回的信息:' +PAnsiChar(string(ReturnInf)));
end;
1:
begin
memo1.Lines.Add('支付宝支付单号:' + trim(edit1.text) + '撒销成功!已触发退款动作,API接口返回的信息:' +PAnsiChar(string(ReturnInf)));
end;
else
begin
memo1.Lines.Add('支付宝支付单号:' + trim(edit1.text) + '撒销失败!API接口返回的信息:' +PAnsiChar(string(ReturnInf)));
end;
end;
except
on E: Exception do
begin
Application.MessageBox(Pchar('支付宝API接口申请操作失败:'+E.Message), '警告', MB_OK+MB_ICONSTOP);
end;
end;

end;

end.