{"rsdb":{"rid":"373456","subhead":"","postdate":"0","aid":"262012","fid":"86","uid":"1","topic":"1","content":"
\n

\u6e90\u7801\u4e0b\u8f7d\u5730\u5740\uff1ahttps:\/\/download.csdn.net\/download\/redhat588\/11798294<\/a><\/strong><\/span><\/p> \n

Delphi xe 10.3.2 for windows 7 \u73af\u5883\u7f16\u8bd1\u901a\u8fc7\uff01<\/p> \n

\u6d4b\u5f0f\u9700\u8981\u5148\u6ce8\u518c\u767e\u5ea6API\u8d26\u53f7\uff0c\u62ff\u5230API KEY \u548cSecret Key\u540e\u624d\u80fd\u83b7\u53d6Token\u503c<\/p> \n

\u7b2c\u4e00\u6b65\uff1a\u9996\u5148\u83b7\u53d6Token\u5730\u5740<\/p> \n

 \"\"<\/p> \n

 <\/p> \n

 <\/p> \n

\n
 1<\/span> function<\/span> TfrmMain.GetToken(TokenUrl, lbledtAPIKEY, lbledtSecretKey\r\n<\/span> 2<\/span>   : string<\/span>): string<\/span>;\r\n<\/span> 3<\/span> begin<\/span>\r\n 4<\/span>   with<\/span> RESTClient1 do<\/span>\r\n 5<\/span>   begin<\/span>\r\n 6<\/span>     BaseURL := TokenUrl;\r\n<\/span> 7<\/span>   end<\/span>;\r\n<\/span> 8<\/span>   with<\/span> RESTRequest1 do<\/span>\r\n 9<\/span>   begin<\/span>\r\n10<\/span>     Method := rmPOST;\r\n<\/span>11<\/span>     AcceptCharSet := '<\/span>utf-8<\/span>'<\/span>;\r\n<\/span>12<\/span>     Params.Clear;\r\n<\/span>13<\/span>     AddParameter('<\/span>grant_type<\/span>'<\/span>, '<\/span>client_credentials<\/span>'<\/span>);\r\n<\/span>14<\/span>     AddParameter('<\/span>client_id<\/span>'<\/span>, lbledtAPIKEY);\r\n<\/span>15<\/span>     \/\/<\/span> API ID   key<\/span>\r\n16<\/span>     AddParameter('<\/span>client_secret<\/span>'<\/span>, lbledtSecretKey);\r\n<\/span>17<\/span>     \/\/<\/span> API secret  key<\/span>\r\n18<\/span>     Execute;\r\n<\/span>19<\/span>     Result := RESTResponse1.Content;\r\n<\/span>20<\/span>   end<\/span>;\r\n<\/span>21<\/span> end<\/span>;\r\n<\/span>22<\/span> \r\n23<\/span> function<\/span> TfrmMain.GetAccessToken(jsonstr: string<\/span>): string<\/span>; \/\/<\/span> \u53d6jsonstring \u503c<\/span>\r\n24<\/span> var<\/span>\r\n25<\/span>   jo: TjsonObject;\r\n<\/span>26<\/span>   jv: TjsonValue;\r\n<\/span>27<\/span> begin<\/span>\r\n28<\/span>   jo := nil<\/span>;\r\n<\/span>29<\/span>   jo := TjsonObject.Create<\/span>;\r\n<\/span>30<\/span>   jo := TjsonObject.parsejsonvalue(Tencoding.utf8.getbytes(jsonstr), 0<\/span>)\r\n<\/span>31<\/span>     as<\/span> TjsonObject;\r\n<\/span>32<\/span>   jv := jo.Get('<\/span>access_token<\/span>'<\/span>).JsonValue;\r\n<\/span>33<\/span>   Result := jv.Value;\r\n<\/span>34<\/span> end<\/span>;\r\n<\/span>35<\/span> \r\n36<\/span> \r\n37<\/span> procedure<\/span> TfrmMain.Button1Click(Sender: TObject);\r\n<\/span>38<\/span> begin<\/span>\r\n39<\/span>   lbledtToken.Text := GetAccessToken(GetToken(lbledtTokenUrl.Text,\r\n<\/span>40<\/span>     lbledtAPIKEY.Text, lbledtSecretKey.Text));\r\n<\/span>41<\/span> end<\/span>;<\/pre> \n <\/div> \n 

 <\/p> \n

\n \u7b2c\u4e8c\u6b65\uff1a\u8bc6\u522b\u8f66\u724c<\/span>\n <\/div> \n
\n
function<\/span> TfrmMain.GetCarNumJson(AccessToken, CarNumAPI: string<\/span>): string<\/span>;\r\n<\/span>var<\/span>\r\n  strtemp: <\/span>string<\/span>;\r\n  temp: TjsonObject;\r\n  strm: TMemoryStream;\r\n  ss: TStringStream;\r\n  s: <\/span>string<\/span>;\r\n<\/span>begin<\/span>\r\n  if<\/span> frmMain.Image1.Picture.Graphic <> nil<\/span> then<\/span>\r\n  begin<\/span>\r\n    strm :<\/span>= TMemoryStream.Create<\/span>;\r\n    frmMain.Image1.Picture.SaveToStream(strm);\r\n    ss :<\/span>= TStringStream.Create<\/span>(''<\/span>);\r\n    strm.Position :<\/span>= 0<\/span>;\r\n    EncodeStream(strm, ss); <\/span>\/\/<\/span> \u5c06\u5185\u5b58\u6d41\u7f16\u7801\u4e3abase64\u5b57\u7b26\u6d41<\/span>\r\n    s := ss.DataString;\r\n    strm.Free;\r\n    ss.Free;\r\n  <\/span>end<\/span>;\r\n  RESTClient1.BaseURL :<\/span>= CarNumAPI;\r\n  RESTRequest1.Params.Clear;\r\n  RESTRequest1.AddParameter(<\/span>'<\/span>access_token<\/span>'<\/span>, AccessToken);\r\n  RESTRequest1.AddParameter(<\/span>'<\/span>image<\/span>'<\/span>, s);\r\n  RESTRequest1.Execute;\r\n  Result :<\/span>= RESTResponse1.Content;\r\n<\/span>end<\/span>;\r\n\r\n<\/span>function<\/span> TfrmMain.GetCarNum(CarNumJSONStr: String): string<\/span>;\r\n<\/span>var<\/span>\r\n  jo: TjsonObject;\r\n  jo2: TjsonObject;\r\n  jv: TjsonValue;\r\n  jsonstr: <\/span>string<\/span>; \/\/<\/span> \u8981\u8f6c\u6362\u7684json\u5b57\u7b26\u4e32<\/span>\r\n  jsonstr2: string<\/span>; \/\/<\/span> \u8981\u8f6c\u6362\u7684json\u5b57\u7b26\u4e32<\/span>\r\nbegin<\/span>\r\n  \/\/<\/span> \u5148\u53d6\u51fa\u5d4c\u5957\u7684\u90a3\u4e2a\u5b57\u7b26\u4e32<\/span>\r\n  jo := TjsonObject.parsejsonvalue(CarNumJSONStr) as<\/span> TjsonObject;\r\n  jsonstr :<\/span>= jo.GetValue('<\/span>words_result<\/span>'<\/span>).ToString;\r\n  <\/span>\/\/<\/span> \u518d\u5bf9\u8fd9\u4e2a\u5b57\u7b26\u4e32\u53d6\u503c<\/span>\r\n  jo2 := TjsonObject.parsejsonvalue(jsonstr) as<\/span> TjsonObject;\r\n  jsonstr2 :<\/span>= jo.GetValue('<\/span>words_result<\/span>'<\/span>).ToString;\r\n  <\/span>try<\/span>\r\n    jv :<\/span>= jo2.Get('<\/span>number<\/span>'<\/span>).JsonValue;\r\n    Result :<\/span>= jv.Value;\r\n  <\/span>finally<\/span>\r\n    jo.Free;\r\n  <\/span>end<\/span>;\r\n<\/span>end<\/span>;\r\n\r\n<\/span>procedure<\/span> TfrmMain.Button2Click(Sender: TObject);\r\n<\/span>begin<\/span>\r\n  lbledtCarNum.Text :<\/span>= GetCarNum(GetCarNumJson(lbledtToken.Text,\r\n    lbledtAPIURL.Text));\r\n<\/span>end<\/span>;<\/pre> \n <\/div> \n 

 <\/p> \n

 <\/p> \n

\u6700\u540e\uff1a\u7ed3\u679c\u56fe<\/p> \n

\"\"<\/p> \n

 <\/p> \n<\/div>","orderid":"0","title":"\u767e\u5ea6API\u8f66\u724c\u8bc6\u522b\u2014\u2014Restful\u65b9\u5f0f","smalltitle":"","mid":"0","fname":"Delphi","special_id":"0","bak_id":"0","info":"0","hits":"290","pages":"1","comments":"0","posttime":"2019-09-23 11:16:24","list":"1569208584","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"\u767e\u5ea6<\/A> API<\/A> \u8f66\u724c<\/A> \u8bc6\u522b<\/A> Restful<\/A> \u65b9\u5f0f<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"14.17.22.33","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"\u767e\u5ea6API\u8f66\u724c\u8bc6\u522b\u2014\u2014Restful\u65b9\u5f0f","lastview":"1713291320","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}