Skip to content

Commit

Permalink
[SVN版本:639]
Browse files Browse the repository at this point in the history
  • Loading branch information
qdac committed Dec 4, 2017
1 parent 410f521 commit 6afe687
Show file tree
Hide file tree
Showing 12 changed files with 496 additions and 184 deletions.
23 changes: 22 additions & 1 deletion Source/QSDK/QSDK.Wechat.ios.pas
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface
SendAuthReq = interface;
WXMediaMessage = interface;

{I 'wxpay.inc'}
{ I 'wxpay.inc' }
/// <summary>微信Api接口函数对象</summary>
WXApi = interface(NSObject) // 在这里声明对象方法(-)
['{D2B85162-56EC-49A1-8147-44FF05A43147}']
Expand Down Expand Up @@ -789,6 +789,7 @@ TiOSWechatService = class(TInterfacedObject, IWechatService)
FMsgId: Integer;
FLastErrorMsg: String;
FLastError: Integer;
FSigner: IWechatSigner;
FRegistered: Boolean;
FOnRequest: TWechatRequestEvent;
FOnResponse: TWechatResponseEvent;
Expand Down Expand Up @@ -826,6 +827,7 @@ TiOSWechatService = class(TInterfacedObject, IWechatService)
procedure setDevId(const AId: String);
function Pay(aprepayId, anonceStr, asign: String;
atimeStamp: Integer): Boolean;
procedure EnableSignCheck(ASigner: IWechatSigner);
function getPayKey: String;
procedure setPayKey(const AKey: String);

Expand Down Expand Up @@ -1009,6 +1011,11 @@ procedure TiOSWechatService.DoReq(P1: BaseReq);
FOnRequest(TiOSWechatRequest.Create(P1));
end;

procedure TiOSWechatService.EnableSignCheck(ASigner: IWechatSigner);
begin
FSigner := ASigner;
end;

function TiOSWechatService.OpenUrl(const AUrl: String): Boolean;
begin

Expand All @@ -1025,6 +1032,7 @@ function TiOSWechatService.Pay(aprepayId, anonceStr, asign: String;
PrepayUrl = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
var
AReq: PayReq;
AExpectSign: String;
begin
AReq := TPayReq.Create;
// AReq .appid := StringToJString(FAppId);
Expand All @@ -1034,6 +1042,19 @@ function TiOSWechatService.Pay(aprepayId, anonceStr, asign: String;
AReq.setNonceStr(StrToNSStr(anonceStr));
AReq.setTimeStamp(atimeStamp);
AReq.setSign(StrToNSStr(asign));
if Assigned(FSigner) then
begin
FSigner.Clear;
FSigner.Add('appid', FAppId);
FSigner.Add('partnerid', FMchId);
FSigner.Add('prepayid', aprepayId);
FSigner.Add('noncestr', anonceStr);
FSigner.Add('package', 'Sign=WXPay');
FSigner.Add('timestamp', IntToStr(atimeStamp));
AExpectSign := FSigner.Sign;
if AExpectSign <> ASign then
raise Exception.CreateFmt(SSignMismatch, [ASign, AExpectSign]);
end;
Debugout('WXPay Start with PrepayId %s,NonceStr %s,Timestamp %d ,Sign %s',
[aprepayId, anonceStr, atimeStamp, asign]);
Result := Registered and TWXApi.OCClass.sendReq(AReq);
Expand Down
32 changes: 28 additions & 4 deletions Source/QSDK/qsdk.wechat.android.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3782,6 +3782,9 @@ implementation
AndroidAPI.Helpers, system.Net.HttpClient, qstring, qxml, qjson, qdigest,
qsdk.wechat;

resourcestring
SSignMismatch = '业务签名校验失败,参数值:%s ,期望值为 %s';

type
TWechatResponse = class(TInterfacedObject, IWechatResponse)
private
Expand Down Expand Up @@ -3827,6 +3830,7 @@ TAndroidWechatService = class(TJavaLocal, IWechatService, JIWXAPIEventHandler)
FOnRequest: TWechatRequestEvent;
FOnResponse: TWechatResponseEvent;
FPayActivity: JActivity;
FSigner: IWechatSigner;
function NextTransaction: String;
function BitmapToArray(ABitmap: TBitmap): TJavaArray<Byte>;
public
Expand Down Expand Up @@ -3857,6 +3861,7 @@ TAndroidWechatService = class(TJavaLocal, IWechatService, JIWXAPIEventHandler)
procedure setDevId(const AId: String);
function Pay(aprepayId, anonceStr, asign: String;
atimeStamp: Integer): Boolean;
procedure EnableSignCheck(ASigner: IWechatSigner);
function getPayKey: String;
procedure setPayKey(const AKey: String);
procedure onReq(P1: JBaseReq); cdecl;
Expand Down Expand Up @@ -4117,6 +4122,11 @@ function TAndroidWechatService.CreateObject(AObjId: TGuid): IWechatObject;
result := TAndroidWechatBaseRequest.Create;
end;

procedure TAndroidWechatService.EnableSignCheck(ASigner: IWechatSigner);
begin
FSigner := ASigner;
end;

function TAndroidWechatService.getAppId: String;
begin
result := FAppId;
Expand Down Expand Up @@ -4215,6 +4225,7 @@ function TAndroidWechatService.Pay(aprepayId, anonceStr, asign: String;
PrepayUrl = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
var
AReq: JPayReq;
AExpectSign: String;
begin
AReq := TJPayReq.JavaClass.init;
AReq.appId := StringToJString(FAppId);
Expand All @@ -4224,6 +4235,19 @@ function TAndroidWechatService.Pay(aprepayId, anonceStr, asign: String;
AReq.nonceStr := StringToJString(anonceStr);
AReq.timeStamp := StringToJString(IntToStr(atimeStamp));
AReq.sign := StringToJString(asign);
if Assigned(FSigner) then
begin
FSigner.Clear;
FSigner.Add('appid', FAppId);
FSigner.Add('partnerid', FMchId);
FSigner.Add('prepayid', aprepayId);
FSigner.Add('noncestr', anonceStr);
FSigner.Add('package', 'Sign=WXPay');
FSigner.Add('timestamp', IntToStr(atimeStamp));
AExpectSign := FSigner.Sign;
if AExpectSign <> ASign then
raise Exception.CreateFmt(SSignMismatch, [ASign, AExpectSign]);
end;
Debugout('WXPay Start with PrepayId %s,NonceStr %s,Timestamp %d ,Sign %s',
[aprepayId, anonceStr, atimeStamp, asign]);
result := Registered and FInstance.sendReq(AReq as JBaseReq);
Expand Down Expand Up @@ -4573,11 +4597,11 @@ constructor TWechatPayResponse.Create(AResp: JBaseResp);
else
FErrorMsg := 'ERR_UNKNOWN';
end;
if ErrorCode = TJBaseResp_ErrCode.JavaClass.ERR_USER_CANCEL then
FPayResult := TWechatPayResult.wprCancel
else
FPayResult := TWechatPayResult.wprError;
end;
if ErrorCode = TJBaseResp_ErrCode.JavaClass.ERR_USER_CANCEL then
FPayResult := TWechatPayResult.wprCancel
else
FPayResult := TWechatPayResult.wprError;
end;

function TWechatPayResponse.getExtData: String;
Expand Down
21 changes: 12 additions & 9 deletions Source/QSDK/qsdk.wechat.pas
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ TWechatOrder = record

TWechatSession = (Session, Timeline, Favorite);

IWechatSigner = interface
['{C06D210C-2DF7-413F-BFE6-E5CEAD764DA1}']
procedure Add(const AKey, AValue: String);
procedure Clear;
function GetSign: String;
function GetKey: String;
property Sign: String read GetSign;
property Key: String read GetKey;
end;

IWechatService = interface
['{10370690-72BC-438C-8105-042D2029B895}']
procedure Unregister;
Expand All @@ -239,6 +249,7 @@ TWechatOrder = record
function CreateObject(AObjId: TGuid): IWechatObject;
function Pay(APrepayId, AnonceStr, ASign: String;
ATimeStamp: Integer): Boolean;
procedure EnableSignCheck(ASigner:IWechatSigner);
function ShareText(ATarget: TWechatSession; const S: String): Boolean;
function ShareWebPage(ATarget: TWechatSession;
const ATitle, AContent, AUrl: String; APicture: TBitmap): Boolean;
Expand All @@ -258,15 +269,7 @@ TWechatOrder = record
write setOnResponse;
end;

IWechatSigner = interface
['{C06D210C-2DF7-413F-BFE6-E5CEAD764DA1}']
procedure Add(const AKey, AValue: String);
procedure Clear;
function GetSign: String;
function GetKey: String;
property Sign: String read GetSign;
property Key: String read GetKey;
end;


TWechatObject = class(TInterfacedObject, IInterface)
protected
Expand Down
2 changes: 1 addition & 1 deletion Source/QWorker.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4211,7 +4211,7 @@ procedure TQWorkers.DoPlanCheck(AJob: PQJob);
Break;
end;
end;
pcrTimeout:
pcrExpired:
begin
if APlan.Runnings = 0 then
begin
Expand Down
Loading

0 comments on commit 6afe687

Please sign in to comment.