parent
8fb4a66109
commit
2cff1a7c0b
@ -0,0 +1,236 @@ |
||||
## Ignore Visual Studio temporary files, build results, and |
||||
## files generated by popular Visual Studio add-ons. |
||||
|
||||
# User-specific files |
||||
*.suo |
||||
*.user |
||||
*.userosscache |
||||
*.sln.docstates |
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio) |
||||
*.userprefs |
||||
|
||||
# Build results |
||||
[Dd]ebug/ |
||||
[Dd]ebugPublic/ |
||||
[Rr]elease/ |
||||
[Rr]eleases/ |
||||
x64/ |
||||
x86/ |
||||
bld/ |
||||
[Bb]in/ |
||||
[Oo]bj/ |
||||
|
||||
# Visual Studio 2015 cache/options directory |
||||
.vs/ |
||||
# Uncomment if you have tasks that create the project's static files in wwwroot |
||||
#wwwroot/ |
||||
|
||||
# MSTest test Results |
||||
[Tt]est[Rr]esult*/ |
||||
[Bb]uild[Ll]og.* |
||||
|
||||
# NUNIT |
||||
*.VisualState.xml |
||||
TestResult.xml |
||||
|
||||
# Build Results of an ATL Project |
||||
[Dd]ebugPS/ |
||||
[Rr]eleasePS/ |
||||
dlldata.c |
||||
|
||||
# DNX |
||||
project.lock.json |
||||
artifacts/ |
||||
|
||||
*_i.c |
||||
*_p.c |
||||
*_i.h |
||||
*.ilk |
||||
*.meta |
||||
*.obj |
||||
*.pch |
||||
*.pdb |
||||
*.pgc |
||||
*.pgd |
||||
*.rsp |
||||
*.sbr |
||||
*.tlb |
||||
*.tli |
||||
*.tlh |
||||
*.tmp |
||||
*.tmp_proj |
||||
*.log |
||||
*.vspscc |
||||
*.vssscc |
||||
.builds |
||||
*.pidb |
||||
*.svclog |
||||
*.scc |
||||
|
||||
# Chutzpah Test files |
||||
_Chutzpah* |
||||
|
||||
# Visual C++ cache files |
||||
ipch/ |
||||
*.aps |
||||
*.ncb |
||||
*.opendb |
||||
*.opensdf |
||||
*.sdf |
||||
*.cachefile |
||||
|
||||
# Visual Studio profiler |
||||
*.psess |
||||
*.vsp |
||||
*.vspx |
||||
*.sap |
||||
|
||||
# TFS 2012 Local Workspace |
||||
$tf/ |
||||
|
||||
# Guidance Automation Toolkit |
||||
*.gpState |
||||
|
||||
# ReSharper is a .NET coding add-in |
||||
_ReSharper*/ |
||||
*.[Rr]e[Ss]harper |
||||
*.DotSettings.user |
||||
|
||||
# JustCode is a .NET coding add-in |
||||
.JustCode |
||||
|
||||
# TeamCity is a build add-in |
||||
_TeamCity* |
||||
|
||||
# DotCover is a Code Coverage Tool |
||||
*.dotCover |
||||
|
||||
# NCrunch |
||||
_NCrunch_* |
||||
.*crunch*.local.xml |
||||
nCrunchTemp_* |
||||
|
||||
# MightyMoose |
||||
*.mm.* |
||||
AutoTest.Net/ |
||||
|
||||
# Web workbench (sass) |
||||
.sass-cache/ |
||||
|
||||
# Installshield output folder |
||||
[Ee]xpress/ |
||||
|
||||
# DocProject is a documentation generator add-in |
||||
DocProject/buildhelp/ |
||||
DocProject/Help/*.HxT |
||||
DocProject/Help/*.HxC |
||||
DocProject/Help/*.hhc |
||||
DocProject/Help/*.hhk |
||||
DocProject/Help/*.hhp |
||||
DocProject/Help/Html2 |
||||
DocProject/Help/html |
||||
|
||||
# Click-Once directory |
||||
publish/ |
||||
|
||||
# Publish Web Output |
||||
*.[Pp]ublish.xml |
||||
*.azurePubxml |
||||
# TODO: Comment the next line if you want to checkin your web deploy settings |
||||
# but database connection strings (with potential passwords) will be unencrypted |
||||
*.pubxml |
||||
*.publishproj |
||||
|
||||
# NuGet Packages |
||||
*.nupkg |
||||
# The packages folder can be ignored because of Package Restore |
||||
**/packages/* |
||||
# except build/, which is used as an MSBuild target. |
||||
!**/packages/build/ |
||||
# Uncomment if necessary however generally it will be regenerated when needed |
||||
#!**/packages/repositories.config |
||||
# NuGet v3's project.json files produces more ignoreable files |
||||
*.nuget.props |
||||
*.nuget.targets |
||||
|
||||
# Microsoft Azure Build Output |
||||
csx/ |
||||
*.build.csdef |
||||
|
||||
# Microsoft Azure Emulator |
||||
ecf/ |
||||
rcf/ |
||||
|
||||
# Microsoft Azure ApplicationInsights config file |
||||
ApplicationInsights.config |
||||
|
||||
# Windows Store app package directory |
||||
AppPackages/ |
||||
BundleArtifacts/ |
||||
|
||||
# Visual Studio cache files |
||||
# files ending in .cache can be ignored |
||||
*.[Cc]ache |
||||
# but keep track of directories ending in .cache |
||||
!*.[Cc]ache/ |
||||
|
||||
# Others |
||||
ClientBin/ |
||||
~$* |
||||
*~ |
||||
*.dbmdl |
||||
*.dbproj.schemaview |
||||
*.pfx |
||||
*.publishsettings |
||||
node_modules/ |
||||
orleans.codegen.cs |
||||
|
||||
# RIA/Silverlight projects |
||||
Generated_Code/ |
||||
|
||||
# Backup & report files from converting an old project file |
||||
# to a newer Visual Studio version. Backup files are not needed, |
||||
# because we have git ;-) |
||||
_UpgradeReport_Files/ |
||||
Backup*/ |
||||
UpgradeLog*.XML |
||||
UpgradeLog*.htm |
||||
|
||||
# SQL Server files |
||||
*.mdf |
||||
*.ldf |
||||
|
||||
# Business Intelligence projects |
||||
*.rdl.data |
||||
*.bim.layout |
||||
*.bim_*.settings |
||||
|
||||
# Microsoft Fakes |
||||
FakesAssemblies/ |
||||
|
||||
# GhostDoc plugin setting file |
||||
*.GhostDoc.xml |
||||
|
||||
# Node.js Tools for Visual Studio |
||||
.ntvs_analysis.dat |
||||
|
||||
# Visual Studio 6 build log |
||||
*.plg |
||||
|
||||
# Visual Studio 6 workspace options file |
||||
*.opt |
||||
|
||||
# Visual Studio LightSwitch build output |
||||
**/*.HTMLClient/GeneratedArtifacts |
||||
**/*.DesktopClient/GeneratedArtifacts |
||||
**/*.DesktopClient/ModelManifest.xml |
||||
**/*.Server/GeneratedArtifacts |
||||
**/*.Server/ModelManifest.xml |
||||
_Pvt_Extensions |
||||
|
||||
# Paket dependency manager |
||||
.paket/paket.exe |
||||
|
||||
# FAKE - F# Make |
||||
.fake/ |
@ -0,0 +1,23 @@ |
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00 |
||||
# Visual Studio 15 |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDKCSharp", "SDKCSharp\SDKCSharp.csproj", "{5461AAE5-F701-4A39-9D81-22BC6A80CFF9}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDKTest", "SDKTest\SDKTest.csproj", "{34D6DDAB-895D-4B31-A18F-157BBF6393A1}" |
||||
EndProject |
||||
Global |
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
||||
Debug|Any CPU = Debug|Any CPU |
||||
Release|Any CPU = Release|Any CPU |
||||
EndGlobalSection |
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
||||
{5461AAE5-F701-4A39-9D81-22BC6A80CFF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{5461AAE5-F701-4A39-9D81-22BC6A80CFF9}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{5461AAE5-F701-4A39-9D81-22BC6A80CFF9}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{5461AAE5-F701-4A39-9D81-22BC6A80CFF9}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{34D6DDAB-895D-4B31-A18F-157BBF6393A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{34D6DDAB-895D-4B31-A18F-157BBF6393A1}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{34D6DDAB-895D-4B31-A18F-157BBF6393A1}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{34D6DDAB-895D-4B31-A18F-157BBF6393A1}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
EndGlobalSection |
||||
EndGlobal |
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,43 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<ProjectGuid>{34D6DDAB-895D-4B31-A18F-157BBF6393A1}</ProjectGuid> |
||||
<OutputType>Exe</OutputType> |
||||
<RootNamespace>SDKTest</RootNamespace> |
||||
<AssemblyName>SDKTest</AssemblyName> |
||||
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>full</DebugType> |
||||
<Optimize>false</Optimize> |
||||
<OutputPath>bin\Debug</OutputPath> |
||||
<DefineConstants>DEBUG;</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
<ExternalConsole>true</ExternalConsole> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||
<Optimize>true</Optimize> |
||||
<OutputPath>bin\Release</OutputPath> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
<ExternalConsole>true</ExternalConsole> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="System" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="Program.cs" /> |
||||
<Compile Include="Properties\AssemblyInfo.cs" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\SDKCSharp\SDKCSharp.csproj"> |
||||
<Project>{5461AAE5-F701-4A39-9D81-22BC6A80CFF9}</Project> |
||||
<Name>SDKCSharp</Name> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> |
||||
</Project> |
@ -0,0 +1,181 @@ |
||||
# sdk-csharp |
||||
|
||||
C#对应的SDK |
||||
|
||||
- SDKCSharp: SDK源码,在此基础上添加接口 |
||||
- SDKTest: 测试用例 |
||||
|
||||
|
||||
## 接口封装步骤 |
||||
|
||||
比如获取故事信息接口 |
||||
|
||||
- 接口名:alipay.story.find |
||||
- 版本号:1.0 |
||||
- 参数:name 故事名称 |
||||
- 返回信息 |
||||
|
||||
``` |
||||
{ |
||||
"alipay_story_find_response": { |
||||
"msg": "Success", |
||||
"code": "10000", |
||||
"name": "白雪公主", |
||||
"id": 1, |
||||
"gmtCreate": 1554193987378 |
||||
}, |
||||
"sign": "xxxxx" |
||||
} |
||||
``` |
||||
|
||||
针对这个接口,封装步骤如下: |
||||
|
||||
1.在`Model`包下新建一个类,定义业务参数 |
||||
|
||||
``` |
||||
namespace SDKCSharp.Model |
||||
{ |
||||
public class GetStoryModel |
||||
{ |
||||
/// <summary> |
||||
/// 故事名称 |
||||
/// </summary> |
||||
/// <value>The name.</value> |
||||
[JsonProperty("name")] |
||||
public string Name { get; set; } |
||||
} |
||||
} |
||||
``` |
||||
|
||||
`[JsonProperty("name")]`是Newtonsoft.Json组件中的类,用于Json序列化,括号中的是参数名称。 |
||||
类似于Java中的注解,`@JSONField(name = "xx")` |
||||
|
||||
2.在`Response`包下新建一个返回类GetStoryResponse,继承`BaseResponse` |
||||
|
||||
里面填写返回的字段 |
||||
|
||||
``` |
||||
namespace SDKCSharp.Response |
||||
{ |
||||
public class GetStoryResponse: BaseResponse |
||||
{ |
||||
[JsonProperty("id")] |
||||
public int Id { get; set; } |
||||
|
||||
[JsonProperty("name")] |
||||
public string Name { get; set; } |
||||
|
||||
[JsonProperty("gmt_create")] |
||||
public string GmtCreate { get; set; } |
||||
|
||||
} |
||||
} |
||||
|
||||
``` |
||||
|
||||
3.在`Request`文件夹下新建一个请求类,继承`BaseRequest` |
||||
|
||||
BaseRequest中有个泛型参数,填`GetStoryResponse`类,表示这个请求对应的返回类。 |
||||
重写`GetMethod()`方法,填接口名。 |
||||
|
||||
如果要指定版本号,可重写`GetVersion()`方法,或者后续使用`request.Version = version`进行设置 |
||||
|
||||
``` |
||||
namespace SDKCSharp.Request |
||||
{ |
||||
public class GetStoryRequest : BaseRequest<GetStoryResponse> |
||||
{ |
||||
public override string GetMethod() |
||||
{ |
||||
return "alipay.story.find"; |
||||
} |
||||
} |
||||
|
||||
} |
||||
``` |
||||
|
||||
|
||||
|
||||
## 使用方式 |
||||
|
||||
``` |
||||
class MainClass |
||||
{ |
||||
static string url = "http://localhost:8081/api"; // zuul |
||||
static string appId = "2019032617262200001"; |
||||
// 支付宝私钥 |
||||
static string privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6UPDfNEnf/K8wX5T4EB1b8x8QJ7Ua4GcIUqeUxGHdQpzNbJdaQvoi06lgccmL+PHzminkFYON7alj1CjDN833j7QMHdPtS9l7B67fOU/p2LAAkPMtoVBfxQt9aFj7B8rEhGCz02iJIBAgMBAAECggEARqOuIpY0v6WtJBfmR3lGIOOokLrhfJrGTLF8CiZMQha+SRJ7/wOLPlsH9SbjPlopyViTXCuYwbzn2tdABigkBHYXxpDV6CJZjzmRZ+FY3S/0POlTFElGojYUJ3CooWiVfyUMhdg5vSuOq0oCny53woFrf32zPHYGiKdvU5Djku1onbDU0Lw8w+5tguuEZ76kZ/lUcccGy5978FFmYpzY/65RHCpvLiLqYyWTtaNT1aQ/9pw4jX9HO9NfdJ9gYFK8r/2f36ZE4hxluAfeOXQfRC/WhPmiw/ReUhxPznG/WgKaa/OaRtAx3inbQ+JuCND7uuKeRe4osP2jLPHPP6AUwQKBgQDUNu3BkLoKaimjGOjCTAwtp71g1oo+k5/uEInAo7lyEwpV0EuUMwLA/HCqUgR4K9pyYV+Oyb8d6f0+Hz0BMD92I2pqlXrD7xV2WzDvyXM3s63NvorRooKcyfd9i6ccMjAyTR2qfLkxv0hlbBbsPHz4BbU63xhTJp3Ghi0/ey/1HQKBgQC2VsgqC6ykfSidZUNLmQZe3J0p/Qf9VLkfrQ+xaHapOs6AzDU2H2osuysqXTLJHsGfrwVaTs00ER2z8ljTJPBUtNtOLrwNRlvgdnzyVAKHfOgDBGwJgiwpeE9voB1oAV/mXqSaUWNnuwlOIhvQEBwekqNyWvhLqC7nCAIhj3yvNQKBgQCqYbeec56LAhWP903Zwcj9VvG7sESqXUhIkUqoOkuIBTWFFIm54QLTA1tJxDQGb98heoCIWf5x/A3xNI98RsqNBX5JON6qNWjb7/dobitti3t99v/ptDp9u8JTMC7penoryLKK0Ty3bkan95Kn9SC42YxaSghzqkt+uvfVQgiNGQKBgGxU6P2aDAt6VNwWosHSe+d2WWXt8IZBhO9d6dn0f7ORvcjmCqNKTNGgrkewMZEuVcliueJquR47IROdY8qmwqcBAN7Vg2K7r7CPlTKAWTRYMJxCT1Hi5gwJb+CZF3+IeYqsJk2NF2s0w5WJTE70k1BSvQsfIzAIDz2yE1oPHvwVAoGAA6e+xQkVH4fMEph55RJIZ5goI4Y76BSvt2N5OKZKd4HtaV+eIhM3SDsVYRLIm9ZquJHMiZQGyUGnsvrKL6AAVNK7eQZCRDk9KQz+0GKOGqku0nOZjUbAu6A2/vtXAaAuFSFx1rUQVVjFulLexkXR3KcztL1Qu2k5pB6Si0K/uwQ="; |
||||
|
||||
|
||||
// 声明一个就行 |
||||
static OpenClient client = new OpenClient(url, appId, privateKey); |
||||
|
||||
public static void Main(string[] args) |
||||
{ |
||||
TestGet(); |
||||
} |
||||
|
||||
// 标准用法 |
||||
private static void TestGet() |
||||
{ |
||||
// 创建请求对象 |
||||
GetStoryRequest request = new GetStoryRequest(); |
||||
// 请求参数 |
||||
GetStoryModel model = new GetStoryModel(); |
||||
model.Name = "白雪公主"; |
||||
request.BizModel = model; |
||||
|
||||
// 发送请求 |
||||
GetStoryResponse response = client.Execute(request); |
||||
|
||||
if (response.IsSuccess()) |
||||
{ |
||||
// 返回结果 |
||||
Console.WriteLine("故事名称:{0}", response.Name); |
||||
} |
||||
else |
||||
{ |
||||
Console.WriteLine("错误, code:{0}, msg:{1}, subCode:{2}, subMsg:{3}", |
||||
response.Code, response.Msg, response.SubCode, response.SubMsg); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
||||
``` |
||||
|
||||
# 使用方式2(懒人版) |
||||
|
||||
如果不想添加Request,Response,Model。可以用这种方式,返回data部分是Dictionary<string, object>,后续自己处理 |
||||
|
||||
``` |
||||
// 懒人版,如果不想添加Request,Response,Model。可以用这种方式,返回全部是String,后续自己处理json |
||||
private static void TestCommon() |
||||
{ |
||||
// 创建请求对象 |
||||
CommonRequest request = new CommonRequest("alipay.story.find"); |
||||
// 请求参数 |
||||
Dictionary<string, string> bizModel = new Dictionary<string, string> |
||||
{ |
||||
["name"] = "白雪公主" |
||||
}; |
||||
|
||||
request.BizModel = bizModel; |
||||
|
||||
// 发送请求 |
||||
CommonResponse response = client.Execute(request); |
||||
|
||||
if (response.IsSuccess()) |
||||
{ |
||||
// 返回结果 |
||||
string body = response.Body; |
||||
Dictionary<string, object> dict = JsonUtil.ParseToDictionary(body); |
||||
Console.WriteLine(dict.ToString()); |
||||
} |
||||
else |
||||
{ |
||||
Console.WriteLine("错误, code:{0}, msg:{1}, subCode:{2}, subMsg:{3}", |
||||
response.Code, response.Msg, response.SubCode, response.SubMsg); |
||||
} |
||||
} |
||||
``` |
Loading…
Reference in new issue