A cikin duniyar da ke ƙara dogaro ga bayanai da musayar bayanai maras kyau, buƙatar samar da ingantacciyar ƙirƙira ba ta taɓa kasancewa mai mahimmanci ba. Barcodes suna aiki azaman yaren duniya don injuna, sauƙaƙe matakai a cikin masana’antu daban-daban. Ko yana bin kaya, sarrafa tallace-tallace, ko inganta tsaro, lambobin sirri suna taka muhimmiyar rawa. A cikin wannan jagorar, za mu bincika yadda ake samar da barcode ba tare da wahala ba ta amfani da API mai ƙarfi .NET REST. Bugu da ƙari, za mu jaddada mahimmancin adana waɗannan mahimman bayanai masu mahimmanci a cikin tsarin JPG masu dacewa da juna, tabbatar da haɗin kai mara kyau da samun dama ga ɗimbin aikace-aikace. da kuma tsarin.
- API ɗin NET REST don Ƙarfin Barcode
- Ƙirƙirar Barcode azaman JPG a cikin C# NET
- Yadda ake Ƙirƙirar Lambar Bar ta amfani da Umarnin CURL
API ɗin NET REST don Ƙarfin Barcode
Samar da barcode tare da daidaito da inganci yana yiwuwa ta hanyar Aspose.BarCode Cloud SDK don NET. Wannan ƙaƙƙarfan kayan haɓaka software yana sauƙaƙa aiwatar da tsarin ƙirƙira lambar sirri, yana ba ku damar haɗa iyawar ƙirƙira lambar lamba cikin ayyukanku ba tare da matsala ba. Har ila yau, yana ba da ikon yanke lambar bariki daga nau’ikan hoto daban-daban, yana ba da damar ingantaccen tsarin kula da lambar sirri. Ko yana ƙirƙirar lambobin QR, UPC-A, Code 39, ko wasu da yawa, wannan SDK yana rufe ɗimbin alamomin lambar lamba.
Domin amfani da SDK, da farko muna buƙatar bincika ‘Aspose.BarCode-Cloud’ a cikin manajan fakitin NuGet kuma danna maɓallin ‘Ƙara Kunshin’. Na biyu, muna buƙatar ziyartar dashboard ɗin girgije, don samun keɓaɓɓen shaidar abokin ciniki.
Ƙirƙirar Barcode azaman JPG a cikin C# NET
Wannan sashe yana bayanin cikakkun bayanai da snippet code da ake buƙata don samar da Barcode ta amfani da C# .NET.
// Don ƙarin samfurori, da fatan za a ziyarci https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-dotnet
// Samu bayanan abokin ciniki daga https://dashboard.aspose.cloud/
string clientSecret = "c71cfe618cc6c0944f8f96bdef9813ac";
string clientID = "163c02a1-fcaa-4f79-be54-33012487e783";
// Misali na tsari inda muka ƙididdige bayanan abokin ciniki don amfani
Configuration configuration = new Configuration()
{
ClientId = clientID,
ClientSecret = clientSecret
};
// ƙirƙirar misali na BarCodeAPI
BarcodeApi barcodeApi = new BarcodeApi(configuration);
// saka nau'in da abun ciki don Barcode
string type = "Code39Standard";
string text = "Hello World...!";
// Barcode tare da rubutu azaman tsakiyar layi kuma a ƙasan lambar barcode
var request = new GetBarcodeGenerateRequest(type, text)
{
TextAlignment = "center",
TextLocation = "Below",
// fitarwa format ga barcode image
format = "JPG"
};
// haifar da Barcode kuma ajiye fitarwa zuwa ma'ajiyar gida
using (Stream response = barcodeApi.GetBarcodeGenerate(request))
{
// tabbatar da tsawon amsa ya fi 0
Assert.IsTrue(response.Length > 0);
// ajiye hoton barcode akan tuƙi na gida
using (FileStream stream = File.Create("BarcodeGenerated.jpg"))
{
response.CopyTo(stream);
}
}
An bayar a ƙasa shine bayanin game da snippet code da aka bayyana a sama.
BarcodeApi barcodeApi = new BarcodeApi(configuration);
Da farko, fara misalin ‘BarcodeApi’ ajin yayin wuce abin’Configuration’ azaman hujja.
var request = new GetBarcodeGenerateRequest(type, text)
{
TextAlignment = "center",
TextLocation = "Below",
format = "JPG"
};
Mun ayyana cewa rubutun da ke cikin lambar barcode zai kasance a ƙasan hoton, daidaitacce a tsakiya kuma tsarin fitarwa zai zama JPG.
Stream response = barcodeApi.GetBarcodeGenerate(request)
Kira API don samar da lambar lamba ta nau’in Code39Standard
.
using (FileStream stream = File.Create("BarcodeGenerated.jpg"))
{
response.CopyTo(stream);
}
Sauƙaƙan yau da kullun don adana sakamako na Barcode a tsarin JPG zuwa faifan gida.
Yadda ake Ƙirƙirar Lambar Bar ta amfani da Umarnin CURL
Samar da lambobin sirri ta amfani da Aspose.BarCode Cloud ta hanyar umarnin cURL hanya ce mai dacewa da inganci. cURL kayan aiki ne na layin umarni da ake amfani da shi don yin buƙatun HTTP, yana mai da shi kyakkyawan zaɓi don haɗawa tare da Aspose.BarCode Cloud API. Bugu da ƙari, tare da umarnin cURL, za ku iya fara buƙatun ƙirƙirar lambar da sauri. Wannan hanyar kuma tana ba ku damar yin aiki da kai da rubuta tsarin tsarawa, sauƙaƙe tsari ko ƙirƙirar lambar lamba mai maimaitawa.
Yanzu, da fatan za a aiwatar da umarni mai zuwa don samar da alamar shiga JWT:
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=163c02a1-fcaa-4f79-be54-33012487e783&client_secret=c71cfe618cc6c0944f8f96bdef9813ac" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Da zarar muna da alamar JWT, da fatan za a aiwatar da umarni mai zuwa don samar da lambar lamba kuma adana abin da aka fitar a kan tuƙi na gida.
curl -v "https://api.aspose.cloud/v3.0/barcode/generate?Type=Code39Standard&Text=Hello%20World..." \
-X GET \
-H "accept: image/jpg" \
-H "authorization: Bearer {accessToken}" \
-o "resultantBarcode.jpg"
Sauya ‘accessToken’ tare da alamar samun damar JWT da aka samar a sama.
Kammalawa
A ƙarshe, samar da lambobin sirri aiki ne mai mahimmanci tare da abubuwan da ke faruwa a sassa daban-daban, daga sarrafa kaya zuwa haɗin gwiwar abokin ciniki. Duk hanyoyin biyu, ta yin amfani da cikakkiyar Aspose.BarCode Cloud SDK don NET da kuma yin amfani da umarnin cURL masu amfani da Aspose.BarCode Cloud, suna ba da mafita mai ƙarfi. Duk da haka, hanyoyin biyu suna haifar da ingantaccen ƙirƙirar lambar lamba, suna ƙarfafa kasuwanci don haɓaka ɓoyayyun bayanai, samun dama, da sarrafa kansa ba tare da matsala ba.
Hanyoyin haɗi masu amfani
Labarai masu alaka
Muna ba da shawarar ziyartar shafukan yanar gizo masu zuwa: