예제 #1
0
        public async Task <string> SendReq(BaseReq request, string targetAppId = ConstantsAPI.WECHAT_APP_ID)
        {
            int p = 0;

            try
            {
                if (request == null)
                {
                    throw new WXException(1, "Req can't be null.");
                }
                if (string.IsNullOrEmpty(targetAppId))
                {
                    throw new WXException(1, "targetAppID can't be empty.");
                }
                p = 1;
                var data = new TransactData
                {
                    Req          = request,
                    AppId        = _appId,
                    ConmandId    = request.Type(),
                    SdkVersion   = ConstantsAPI.SDK_VERSION,
                    CheckContent = GetCheckContent()
                };
                data.CheckSummary = GetCheckSummary(data.CheckContent, data.SdkVersion, data.AppId);
                p = 2;
                if (string.IsNullOrEmpty(request.Transaction))
                {
                    request.Transaction = GetTransactionId();
                }

                var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(ConstantsAPI.SDK_TEMP_DIR_PATH, CreationCollisionOption.OpenIfExists);

                p = 3;
                string fileName = $"{TempFileName}.{targetAppId}";
                //if (await FileUtil.fileExists(fileName))
                //{
                //   await FileUtil.deleteFile(fileName);
                //}
                if (data.ValidateData(false))
                {
                    try
                    {
                        p = 4;
                        TransactData.WriteToFile(data, fileName, ConstantsAPI.SDK_TEMP_DIR_PATH);
                        SendOut(fileName, targetAppId);
                        return("true");
                    }
                    catch (Exception exception)
                    {
                        throw new WXException(0, exception.Message);
                    }
                }
                return("false");
            }
            catch (Exception e)
            {
                return(e.Message + "p:" + p);
            }
        }
예제 #2
0
        public async void ParseData(StorageFile file)
        {
            try
            {
                if (!await FileUtil.DirExists(ConstantsAPI.SDK_TEMP_DIR_PATH))
                {
                    await FileUtil.CreateDir(ConstantsAPI.SDK_TEMP_DIR_PATH);
                }

                var folder = await ApplicationData.Current.LocalFolder.GetFolderAsync(ConstantsAPI.SDK_TEMP_DIR_PATH);

                var copyFile = await file.CopyAsync(folder, "wp.wechat", NameCollisionOption.ReplaceExisting);

                if (await FileUtil.FileExists(ConstantsAPI.SDK_TEMP_FILE_PATH))
                {
                    TransactData data = await TransactData.ReadFromFile(ConstantsAPI.SDK_TEMP_FILE_PATH);

                    if (!data.ValidateData())
                    {
                        //MessageBox.Show("数据验证失败");
                    }
                    else if (!data.CheckSupported())
                    {
                        //MessageBox.Show("当前版本不支持该请求");
                    }
                    else if (data.Req != null)
                    {
                        if (data.Req.Type() == ConstantsAPI.COMMAND_GETMESSAGE_FROM_WX)
                        {
                            OnGetMessageFromWXRequest(data.Req as GetMessageFromWX.Req);
                        }
                        else if (data.Req.Type() == 4)
                        {
                            OnShowMessageFromWXRequest(data.Req as ShowMessageFromWX.Req);
                        }
                    }
                    else if (data.Resp != null)
                    {
                        if (data.Resp.Type() == 1)
                        {
                            OnSendAuthResponse(data.Resp as SendAuth.Resp);
                        }
                        else if (data.Resp.Type() == 2)
                        {
                            OnSendMessageToWXResponse(data.Resp as SendMessageToWX.Resp);
                        }
                        else if (data.Resp.Type() == 5)
                        {
                            OnSendPayResponse(data.Resp as SendPay.Resp);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                //MessageBox.Show(exception.Message);
            }
        }
예제 #3
0
        public async Task<string> SendReq(BaseReq request, string targetAppId = ConstantsAPI.WECHAT_APP_ID)
        {
            int p = 0;
            try
            {
                if (request == null)
                {
                    throw new WXException(1, "Req can't be null.");
                }
                if (string.IsNullOrEmpty(targetAppId))
                {
                    throw new WXException(1, "targetAppID can't be empty.");
                }
                p = 1;
                var data = new TransactData
                {
                    Req = request,
                    AppId = _appId,
                    ConmandId = request.Type(),
                    SdkVersion = ConstantsAPI.SDK_VERSION,
                    CheckContent = GetCheckContent()
                };
                data.CheckSummary = GetCheckSummary(data.CheckContent, data.SdkVersion, data.AppId);
                p = 2;
                if (string.IsNullOrEmpty(request.Transaction))
                {
                    request.Transaction = GetTransactionId();
                }

                var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(ConstantsAPI.SDK_TEMP_DIR_PATH, CreationCollisionOption.OpenIfExists);
                p = 3;
                string fileName = $"{TempFileName}.{targetAppId}";
                //if (await FileUtil.fileExists(fileName))
                //{
                //   await FileUtil.deleteFile(fileName);
                //}
                if (data.ValidateData(false))
                {
                    try
                    {
                        p = 4;
                        TransactData.WriteToFile(data, fileName, ConstantsAPI.SDK_TEMP_DIR_PATH);
                        SendOut(fileName, targetAppId);
                        return "true";
                    }
                    catch (Exception exception)
                    {
                        throw new WXException(0, exception.Message);
                    }
                }
                return "false";
            }
            catch (Exception e)
            {
                return e.Message + "p:" + p;
            }
        }
예제 #4
0
 private async void parseData(string fileToken)
 {
     try
     {
         StorageFolder localFolder = ApplicationData.Current.LocalFolder;
         if (!FileUtil.dirExists("wechat_sdk"))
         {
             FileUtil.createDir("wechat_sdk");
         }
         await(await SharedStorageAccessManager.RedeemTokenForFileAsync(fileToken)).CopyAsync(localFolder, "wechat_sdk\\wp.wechat", NameCollisionOption.ReplaceExisting);
         //await SharedStorageAccessManager.CopySharedFileAsync(localFolder, "wechat_sdk\\wp.wechat", 1, fileToken);
         if (FileUtil.fileExists("wechat_sdk\\wp.wechat"))
         {
             TransactData transactData = TransactData.ReadFromFile("wechat_sdk\\wp.wechat");
             if (!transactData.ValidateData(true))
             {
                 await new Windows.UI.Popups.MessageDialog("数据验证失败").ShowAsync();
             }
             else if (!transactData.CheckSupported())
             {
                 await new Windows.UI.Popups.MessageDialog("当前版本不支持该请求").ShowAsync();
             }
             else if (transactData.Req != null)
             {
                 if (transactData.Req.Type() == 3)
                 {
                     this.On_GetMessageFromWX_Request(transactData.Req as GetMessageFromWX.Req);
                 }
                 else if (transactData.Req.Type() == 4)
                 {
                     this.On_ShowMessageFromWX_Request(transactData.Req as ShowMessageFromWX.Req);
                 }
             }
             else if (transactData.Resp != null)
             {
                 if (transactData.Resp.Type() == 2)
                 {
                     this.On_SendMessageToWX_Response(transactData.Resp as SendMessageToWX.Resp);
                 }
                 else if (transactData.Resp.Type() == 1)
                 {
                     this.On_SendAuth_Response(transactData.Resp as SendAuth.Resp);
                 }
                 else if (transactData.Resp.Type() == 5)
                 {
                     this.On_SendPay_Response(transactData.Resp as SendPay.Resp);
                 }
             }
         }
     }
     catch
     {
         await new Windows.UI.Popups.MessageDialog("未知错误").ShowAsync();
     }
 }
예제 #5
0
        public async static void WriteToFile(TransactData data, string fileName, string folderName)
        {
            byte[] destinationArray = new byte[0x40];
            destinationArray[0] = 1;
            destinationArray[1] = 5;
            byte[] buffer2 = data.ToProto().ToByteArray();
            int    length  = buffer2.Length;

            Array.Copy(BitConverter.GetBytes(length), 0, destinationArray, 2, 4);
            await FileUtil.WriteToFile(fileName, folderName, destinationArray, true);

            FileUtil.AppendToFile(fileName, folderName, buffer2);
        }
예제 #6
0
        public async static Task <TransactData> ReadFromFile(string fileName)
        {
            byte[] sourceArray = await FileUtil.ReadFromFile(fileName, 0, 0x40);

            byte[] destinationArray = new byte[4];
            Array.Copy(sourceArray, 2, destinationArray, 0, 4);
            int           count    = BitConverter.ToInt32(destinationArray, 0);
            TransactDataP protoObj = TransactDataP.ParseFrom((await FileUtil.ReadFromFile(fileName, 0x40, count)));
            TransactData  data     = new TransactData();

            data.FromProto(protoObj);
            return(data);
        }
예제 #7
0
        public static TransactData ReadFromFile(string filePath)
        {
            byte[] array  = FileUtil.readFromFile(filePath, 0, 64);
            byte[] array2 = new byte[4];
            Array.Copy(array, 2, array2, 0, 4);
            int count = BitConverter.ToInt32(array2, 0);

            byte[]        data         = FileUtil.readFromFile(filePath, 64, count);
            TransactDataP protoObj     = TransactDataP.ParseFrom(data);
            TransactData  transactData = new TransactData();

            transactData.FromProto(protoObj);
            return(transactData);
        }
예제 #8
0
        public static void WriteToFile(TransactData data, string filePath)
        {
            byte[] array = new byte[64];
            array[0] = 1;
            array[1] = 5;
            TransactDataP transactDataP = data.ToProto();

            byte[] array2 = transactDataP.ToByteArray();
            int    num    = array2.Length;

            byte[] bytes = BitConverter.GetBytes(num);
            Array.Copy(bytes, 0, array, 2, 4);
            FileUtil.writeToFile(filePath, array, true);
            FileUtil.appendToFile(filePath, array2);
        }
예제 #9
0
        public async Task <bool> SendResp(BaseResp response, string targetAppId)
        {
            if (response == null)
            {
                throw new WXException(1, "Resp can't be null.");
            }
            if (string.IsNullOrEmpty(targetAppId))
            {
                throw new WXException(1, "targetAppID can't be empty.");
            }
            var data = new TransactData
            {
                Resp         = response,
                AppId        = _appId,
                ConmandId    = response.Type(),
                SdkVersion   = ConstantsAPI.SDK_VERSION,
                CheckContent = GetCheckContent(),
                CheckSummary = GetCheckSummary(GetCheckContent(), ConstantsAPI.SDK_VERSION, _appId)
            };

            if (string.IsNullOrEmpty(response.Transaction))
            {
                response.Transaction = GetTransactionId();
            }

            var folder = await ApplicationData.Current.LocalFolder.CreateFileAsync(ConstantsAPI.SDK_TEMP_DIR_PATH);

            string fileName = $"{TempFileName}.{targetAppId}";

            //if (await FileUtil.fileExists(fileName))
            //{
            //   await FileUtil.deleteFile(fileName);
            //}
            if (data.ValidateData(false))
            {
                try
                {
                    TransactData.WriteToFile(data, fileName, ConstantsAPI.SDK_TEMP_DIR_PATH);
                    SendOut(fileName, targetAppId);
                    return(true);
                }
                catch (Exception exception)
                {
                    throw new WXException(0, exception.Message);
                }
            }
            return(false);
        }
예제 #10
0
        public bool SendResp(BaseResp response, string targetAppID)
        {
            if (response == null)
            {
                throw new WXException(1, "Resp can't be null.");
            }
            if (string.IsNullOrEmpty(targetAppID))
            {
                throw new WXException(1, "targetAppID can't be empty.");
            }
            TransactData transactData = new TransactData();

            transactData.Resp         = response;
            transactData.AppID        = this.mAppID;
            transactData.ConmandID    = response.Type();
            transactData.SdkVersion   = "1.5";
            transactData.CheckContent = WXApiImplV1.getCheckContent();
            transactData.CheckSummary = WXApiImplV1.getCheckSummary(transactData.CheckContent, transactData.SdkVersion, transactData.AppID);
            if (string.IsNullOrEmpty(response.Transaction))
            {
                response.Transaction = WXApiImplV1.getTransactionId();
            }
            if (!FileUtil.dirExists("wechat_sdk"))
            {
                FileUtil.createDir("wechat_sdk");
            }
            string text = "wechat_sdk\\wp." + targetAppID;

            if (FileUtil.fileExists(text))
            {
                FileUtil.deleteFile(text);
            }
            if (transactData.ValidateData(false))
            {
                try
                {
                    TransactData.WriteToFile(transactData, text);
                    this.sendOut(text, targetAppID);
                    return(true);
                }
                catch (Exception ex)
                {
                    throw new WXException(0, ex.Message);
                }
                //return false;
            }
            return(false);
        }
예제 #11
0
        public async Task<bool> SendResp(BaseResp response, string targetAppId)
        {
            if (response == null)
            {
                throw new WXException(1, "Resp can't be null.");
            }
            if (string.IsNullOrEmpty(targetAppId))
            {
                throw new WXException(1, "targetAppID can't be empty.");
            }
            var data = new TransactData
            {
                Resp = response,
                AppId = _appId,
                ConmandId = response.Type(),
                SdkVersion = ConstantsAPI.SDK_VERSION,
                CheckContent = GetCheckContent(),
                CheckSummary = GetCheckSummary(GetCheckContent(), ConstantsAPI.SDK_VERSION, _appId)
            };
            if (string.IsNullOrEmpty(response.Transaction))
            {
                response.Transaction = GetTransactionId();
            }

            var folder = await ApplicationData.Current.LocalFolder.CreateFileAsync(ConstantsAPI.SDK_TEMP_DIR_PATH);

            string fileName = $"{TempFileName}.{targetAppId}";
            //if (await FileUtil.fileExists(fileName))
            //{
            //   await FileUtil.deleteFile(fileName);
            //}
            if (data.ValidateData(false))
            {
                try
                {
                    TransactData.WriteToFile(data, fileName, ConstantsAPI.SDK_TEMP_DIR_PATH);
                    SendOut(fileName, targetAppId);
                    return true;
                }
                catch (Exception exception)
                {
                    throw new WXException(0, exception.Message);
                }
            }
            return false;
        }
예제 #12
0
 public async static void WriteToFile(TransactData data, string fileName, string folderName)
 {
     byte[] destinationArray = new byte[0x40];
     destinationArray[0] = 1;
     destinationArray[1] = 5;
     byte[] buffer2 = data.ToProto().ToByteArray();
     int length = buffer2.Length;
     Array.Copy(BitConverter.GetBytes(length), 0, destinationArray, 2, 4);
     await FileUtil.WriteToFile(fileName, folderName, destinationArray, true);
     FileUtil.AppendToFile(fileName, folderName, buffer2);
 }
예제 #13
0
 public async static Task<TransactData> ReadFromFile(string fileName)
 {
     byte[] sourceArray = await FileUtil.ReadFromFile(fileName, 0, 0x40);
     byte[] destinationArray = new byte[4];
     Array.Copy(sourceArray, 2, destinationArray, 0, 4);
     int count = BitConverter.ToInt32(destinationArray, 0);
     TransactDataP protoObj = TransactDataP.ParseFrom((await FileUtil.ReadFromFile(fileName, 0x40, count)));
     TransactData data = new TransactData();
     data.FromProto(protoObj);
     return data;
 }