Payment for Windows 8 stores

Source: Internet
Author: User

When developing applications, it is inevitable that you want to earn a certain amount of food expenses, that is, the so-called paid applications. In Windows 8, applications and applications are charged.

The app charge is very simple. Set the country when the app publishes the 'sale detail' and set the amount, as shown in figure

Then, wait for the user to click buy. Of course, you can also add trial functions.

If you choose to pay for the application, you canProgramObtain the license of the current application (containing application-related information), which can be used to determine whether the current application is in trial status and has a valid certificate date.

If you want to add in-app charges, you need to declare when uploading, that is, where the 'advanced functions' is like

The product ID must be a string and unique (relative to this application ).CodeTo obtain the relevant information.

When you add a product ID, you need to provide a description on where to add the product ID.

Well, the configuration of the application released in the store has been completed. When the program is debugging, we cannot get the configuration just filled in above. So we should use the currentappsimulator object during development.

The description of msdn is as follows:

Until the application is in the Windows Storage list,CurrentappThe object does not work in the application. UseCurrentappsimulatorTest the application authorization and obtain it from the application. After the application is tested and submitted to Windows StoreCurrentappsimulatorTo replaceCurrentapp. If you useCurrentappsimulatorYour application cannot pass authentication.

Note:When using a simulation, the initial allowable state of the application is described in windowsstoreproxy. xml. To change the license statusCurrentappsimulatorMethods (such as purchasing a license or purchasing within a handler) can only update the license status of objects in the memory. The content of windowsstoreproxy. XML is not changed. When the application is started again, the license status is restored to the one described in windowsstoreproxy. xml.

CurrentappsimulatorThe object obtains its data from the windowsstoreproxy. xml file in the % USERPROFILE % \ appdata \ Local \ packages \ <package-moniker> \ localstate \ Microsoft \ Windows Store \ apidata folder. You mustCurrentappsimulatorProperty to simulate the scheme to configure this file.

 

Generally, you need to create a windowsstoreproxy. xml file in the program path to describe the payment using the simulator. The path of this file has been pointed out above (copy % USERPROFILE % \ appdata \ Local \ packages \, paste the content in the address bar of the resource manager to jump to the local independent storage directory of the application without the package name. You can create or not (the system will automatically create the package ).

If you publish the information to the store, the configuration information will be generated.

Okay, go to the code.

Three textblocks are added to the front-end to display the current application information and product purchase information, and three buttons are used to purchase the application Purchase Product and update information:

View code

1 <stackpanel verticalalignment = "center" horizontalalignment = "center"> 2 <textblock X: Name = "appinfo" fontsize = "25"/> 3 <textblock X: name = "productinfo" fontsize = "25"/> 4 <button content = "buy an application" X: name = "btn_buyapp" Click = "btn_buy_click"/> 5 <button content = "buy product" X: name = "btn_buyproduct" Click = "btn_buyproduct_click"/> 6 <button content = "update information" X: name = "btn_update" Click = "btn_update_click_1"/> 7 <textblock fontsize = "25" X: Name = "tb_info"/> 8 </stackpanel>

First, you must understand the following two classes. These two classes have the same letters as 90%.

Data that can be found in the licenseinformation Summary (current name of the application, number of charged items, etc)

Listinginformation details the available license data of the application (whether the application is currently purchased or not, and the status of the purchased project, etc)

 

Use Windows. ApplicationModel. Store. currentappsimulator. licenseinformation; // obtain the license information of the current application from the simulator.

Use Windows. ApplicationModel. Store. currentapp. licenseinformation; // obtain the license information of the current application from Windows Store.

Note until the application is in the Windows Storage list,CurrentappThe object does not work in the application, so windows. ApplicationModel. Store. currentappsimulator. licenseinformation should be used in debug.

This can be written in the code.

 
# If debug // call the simulator if it is in the debugging status; otherwise, it will... licenseinfo = windows. applicationModel. store. currentappsimulator. licenseinformation; # elselicenseinfo = windows. applicationModel. store. currentapp. licenseinformation; # endif

When using Windows. applicationModel. store. currentappsimulator. the application automatically detects % USERPROFILE % \ appdata \ Local \ packages \ <package-moniker> \ localstate \ Microsoft \ Windows Store \ apidata.

That is, whether the windowsstoreproxy. xml file in the localstate of the current application exists. If yes, load the file or create one (and write the initial data)

It should look like this

View code

1 <? XML version = "1.0" encoding = "UTF-16"?> 2 <currentapp> 3 <listinginformation> 4 <app> 5 <appid> 00000000-0000-0000-0000-000000000000 </appid> 6 <linkuri> http://apps.microsoft.com/webpdp/app/00000000-0000-0000-0000-000000000000 </linkuri> 7 <currentmarket> en-US </currentmarket> 8 <agerating> 3 </agerating> 9 <marketdata XML: lang = "En-us"> 10 <Name> appname </Name> 11 <description> appdescription </description> 12 <price> 1.00 </price> 13 <currencysymbol> $ </currencysymbol> 14 <currencycode> USD </currencycode> 15 </marketdata> 16 </APP> 17 <product productid = "1" licenseduration = "0"> 18 <marketdata XML: lang = "En-us"> 19 <Name> product1name </Name> 20 <price> 1.00 </price> 21 <currencysymbol >$ </currencysymbol> 22 <currencycode> USD </currencycode> 23 </marketdata> 24 </product> 25 </listinginformation> 26 <licenseinformation> 27 <app> 28 <isactive> true </isactive> 29 <istrial> true </istrial> 30 </APP> 31 <product productid = "1"> 32 <isactive> true </isactive> 33 </product> 34 </licenseinformation> 35 </currentapp>

Then I changed him to a product that is in trial and is not activated and has a product ID of product1. The price of '10 buy a full version' is 10.00. The price of not buying the current application is 10 USD.. The following are my modified

For introduction to this XML file, click the connection below

Click me

Modified

1 <? XML version = "1.0" encoding = "UTF-16"?> 2 <currentapp> 3 <listinginformation> 4 <app> 5 <appid> 9ee87f78-ab14-4cdc-9ba1-0bc20a021054 </appid> 6 <linkuri> http://apps.microsoft.com/webpdp/app/9ee87f78-ab14-4cdc-9ba1-0bc20a021054 </linkuri> 7 <currentmarket> en-US </currentmarket> 8 <agerating> 3 </agerating> 9 <marketdata XML: lang = "En-us"> 10 <Name> you cannot afford 10 yuan, cannot be bought. </Name> 11 <description> application purchase </description> 12 <price> 10.00 </price> 13 <currencysymbol >$ </currencysymbol> 14 <currencycode> USD </currencycode> 15 </marketdata> 16 </APP> 17 <product productid = "product1" licenseduration = "10"> 18 <marketdata XML: lang = "En-us"> 19 <Name> 10. Buy the full version </Name> 20 <price> 10.00 </price> 21 <currencysymbol >$ </currencysymbol> 22 <currencycode> USD </currencycode> 23 </marketdata> 24 </product> 25 </listinginformation> 26 <licenseinformation> 27 <app> 28 <isactive> false </isactive> 29 <istrial> true </istrial> 30 </APP> 31 <product productid = "product1"> 32 <isactive> false </isactive> 33 </product> 34 </licenseinformation> 35 </currentapp>

Then you can write in the Code as follows:

Use Windows. ApplicationModel. Store. currentappsimulator. licenseinformation; obtain licenseinformation)

Use await windows. ApplicationModel. Store. currentappsimulator. loadlistinginformationasync (); listinginformation (details)

Write a method to obtain information to update information (note licenseinformation and listinginformation)

View code

1 private async system. threading. tasks. task getlicenseinfo () 2 {3 4 # If debug 5 // call the simulator if it is in debugging status; otherwise, xxoo 6 licenseinfo = windows. applicationModel. store. currentappsimulator. licenseinformation; 7 # else 8 licenseinfo = windows. applicationModel. store. currentapp. licenseinformation; 9 # endif10 # If debug11 listinginfo = await windows. applicationModel. store. currentappsimulator. loadlistinginformationasync (); 12 # else13 listinginfo = await windows. applicationModel. store. currentapp. loadlistinginformationasync (); 14 # endif15 16 appinfo. TEXT = "Current Application Status:"; 17 appinfo. text + = (licenseinfo. isactive = true? "Activated,": "not activated,"); // obtain the overview information to see if 18 appinfo. Text + = (licenseinfo. istrial = true? "Trial period. ":" No trial period. "); // obtain the overview information to see if the current application is in trial 19 20 21 var product1 = listinginfo. productlistings ["product1"]; // obtain the information of product1 in detail. In the store, 'advanced function' configures 22 23 productinfo. TEXT = "purchased products:"; 24 productinfo. text + = "\" "+ product1.name +" \ ""; 25 productinfo. text + = "Price:" + product1.formattedprice; // you cannot afford 10 yuan, but you cannot afford 26 productinfo for 10 yuan. text + = "status:" + (licenseinfo. productlicenses ["product1"]. isactive = true? "Purchased": "Not purchased"); 27}

Then, you can use a more defined product ID to implement the in-house purchase function as follows:

 
String receipt = ""; # If debug receept = await currentappsimulator. requestproductpurchaseasync ("product1", true); // The first parameter is the product ID. The second parameter is whether to return the invoice (some information). Generally, it is false # else await currentapp. requestproductpurchaseasync ("product1", false); # endif

 

View code

1 // In-APP purchase function 2 var product1 = licenseinfo. productlicenses ["product1"]; // obtain product1 Information 3 4 If (! Product1.isactive) 5 {6 tb_info.text = "purchasing products"; 7 Try 8 {9 10 string receept = ""; 11 # If debug12 receept = await currentappsimulator. requestproductpurchaseasync ("product1", true); // The first parameter is the product ID. The second parameter is whether to return the invoice. Generally, it is false13 # else14 await currentapp. requestproductpurchaseasync ("product1", false); 15 # endif16 if (licenseinfo. productlicenses ["product1"]. isactive) 17 {18 tb_info.text = "purchase successful! "; 19 Debug. writeline (" Print invoice: "+ receipt); 20} 21 22} 23 catch (exception) 24 {25 tb_info.text =" no purchase successful! "; 26} 27} 28 else29 {30 tb_info.text =" you have purchased this function! "; 31}

You can also purchase applications.

 
1 string receept = ""; 2 # If debug3 receept = await currentappsimulator. requestapppurchaseasync (true); // purchase an application with an invoice! 4 # else5 await currentapp. requestapppurchaseasync (false); 6 # endif

 

View code

1 If (licenseinfo. istrial) 2 {3 try 4 {5 6 string receept = ""; 7 # If debug 8 receept = await currentappsimulator. requestapppurchaseasync (true); // an invoice is required for purchasing an application! 9 # else10 await currentapp. requestapppurchaseasync (false); 11 # endif12 if (licenseinfo. isactive) 13 {14 tb_info.text = "purchase successful! "; 15 Debug. writeline (" Print invoice: "+ receipt); 16} 17} 18 catch (exception) 19 {20 tb_info.text =" no purchase successful! "; 21} 22 23} 24 else25 {26 tb_info.text =" How much is the money? You have purchased this application! "; 27}

Note that

When using a simulation, the initial allowable state of the application is described in windowsstoreproxy. xml. The currentappsimulator Method for changing the license status (for example, by buying a license or purchasing within the processing program) can only update the license status of objects in the memory. The content of windowsstoreproxy. XML is not changed. When the application is started again, the license status is restored to the one described in windowsstoreproxy. xml

If it is released to the store, it should be stored in the system (I have not tested it) and it is safer than storing it in other locations.

Do not save the status to applicationdata. Current. localsettings or other setting when determining whether a user has purchased an application or purchased an in-house purchase. This is quite insecure! Encryption is not secure!

The settings. dat file in the settings folder under the installation path of the application package is the location where setting is stored. Microsoft has not encrypted it! Copy to another program and write a traversal ....

The running result is as follows:

The corresponding information can be returned in the simulator.

For the windowsstoreproxy. xml file, you can use currentappsimulator. reloadsimulatorasync to load a custom XML file, which is described in Microsoft's demo.

On the whole, it seems that the payment mode of Windows 8 is not safe. Some time ago, foreign hackers have provided tools to turn paid applications into purchased ones, and they are still open-source...

I heard that Sina has a payment system that looks awesome ..

If anyone has a better solution, please feel free to let me know.

 

PS: A good application can make profits even if it is free of charge!

 

you are welcome to repost this article. For more information, see the blog from beyondblog.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.