Cocos2d-x and Android mixed editing realize game payment function

Source: Internet
Author: User

The payment on the game payment platform is actually a "third-party intermediary" in the transaction process between buyers and sellers, or a "Technical intermediary ". Here I select the pods SDK platform to implement the game payment function.


Payment process:

Configure the game server callback Address URL the game client uses the applied Appkey_id. After the secretkey game client uses the doLogin method to call the onSuccess method, the game client submits user information (uid, nick, to the game server. The game server submits the uid and token to the pea pod server for verification. After the verification is passed, the game completes logon. If a role is created, the game client calls the createRole method to create the role, register with the pods server. You can call the game client to create an order and set the order number (order. out_trade_no), initiate a payment (pay) for the player to complete the payment, and return to the game client for only successful payment orders. The pods server notifies the game server of the callback address, including the order. out_trade_no: The game server verifies the signature in the callback information. You can use the public key in the RsaTest project. After the verification is passed, the game channel is issued to the game client and the success string is returned, if the processing fails, the return value is the fail string. The game client starts to use the channel.

Note:




For more information about how to add the pod SDK, see technical documentation.

Let's take a look at my directory structure:


<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Vcd48cd4gicagicagicagicagicagicagicagicagicagicagidxpbwcgc3jjjpq = "http://www.2cto.com/uploadfile/Collfiles/20140403/201404030913357.jpg" alt = "\"/>


Is it similar to the previous blog? Is the cocos2d-x and Android mixed encoding to achieve "avatar picture "! By the way, the basic implementation ideas are the same, cocos2d-x controls trigger call android method implementation.

Because it is the same as the previous blog step, I will not talk about it more. Then I will upload the code for your reference.


Payment function: PayDemo. java

Package com. wandoujia. wdpaydemo. wdj; import android. app. activity; import android. OS. bundle; import android. OS. handler; import android. OS. logoff; import android. util. log; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. textView; import com. wandoujia. sdk. plugin. paydef. loginCallBack; import com. wandoujia. sdk. plugin. paydef. payCallBack; import Com. wandoujia. sdk. plugin. paydef. user; import com. wandoujia. sdk. plugin. paydef. wandouAccount; import com. wandoujia. sdk. plugin. paydef. wandouOrder; import com. wandoujia. sdk. plugin. paydef. wandouPay; import com. wandoujia. sdk. plugin. paysdkimpl. payConfig; import com. wandoujia. sdk. plugin. paysdkimpl. wandouAccountImpl; import com. wandoujia. sdk. plugin. paysdkimpl. wandouPayImpl; import com. wandoujia. wandoujiapaymentpl Ugin. utils. MSG; public class PayDemo extends Activity implements OnClickListener {private static final String TAG = "PayDemo"; final String appkey_id = "100000000 "; // developer security key final String secretkey = "secret"; private WandouAccount account = new WandouAccountImpl (); private WandouPay wandoupay = new secret (); @ Override protected void onCreate (Bundle savedInstance State) {Log. e (TAG, "start onCreate ~~~ "+ Android. OS. build. VERSION. RELEASE); super. onCreate (savedInstanceState); // call PayConfig in onCreate. init initializes PayConfig. init (this, appkey_id, secretkey); gameLayout () ;}@ Override protected void onDestroy () {super. onDestroy (); Log. e (TAG, "start onDestroy ~~~ "+ Android. OS. build. VERSION. RELEASE);} public void gameLayout () {setContentView (R. layout. activity_main); (Button) findViewById (R. id. pay )). setOnClickListener (this); (Button) findViewById (R. id. login_button )). setOnClickListener (this); (Button) findViewById (R. id. logout_button )). setOnClickListener (this);} public String textString (int id) {return (TextView) findViewById (id )). getText (). toString () ;} Public void setText (final int id, final String str) {// Request UI update on main thread. new Handler (logoff. getMainLooper ()). post (new Runnable () {@ Override public void run () {(TextView) findViewById (id )). setText (str) ;}}) ;}@ Override public void onClick (View v) {int viewId = v. getId (); if (R. id. pay = viewId) {Log. w (TAG, "doPayment! "); Float money = Float. parseFloat (textString (R. id. money); long moneyInFen = (long) (money * 100); WandouOrder order = new WandouOrder (textString (R. id. subject), textString (R. id. desc), moneyInFen); // set the game order number, which can contain up to 50 characters. setOut_trade_no ("GameOrderIdMaxLenth50"); // trigger the payment of wandoupay. pay (PayDemo. this, order, new PayCallBack () {@ Override public void onSuccess (User user, WandouOrder order) {Log. w ("De MoPay "," onSuccess: "+ order); setText (R. id. orderInfo, user. getNick () +" Payment successful! "+ Order) ;}@ Override public void onError (User user, WandouOrder order) {Log. w ("DemoPay", "onError:" + order); setText (R. id. orderInfo, user. getNick () + "Payment failed! "+ Order) ;}}) ;}else if (R. id. login_button = viewId) {Log. I (TAG, "PaySdk init. "); // PayConfig. init (this, appkey_id, secretkey); Log. w (TAG, "doLogin! "); // Trigger Logon account. doLogin (PayDemo. this, new LoginCallBack () {@ Override public void onSuccess (User user, int type) {Log. w ("login", "success: +" + user); setText (R. id. account, user. toString (); // dolphin pod Account UID Long uid = user. getUid (); // String nick = user. getNick (); // Token for login verification of the pods account. Valid String token = user within 15 minutes. getToken (); // 1. please submit uid and token to the game server // 2. the game server receives the uid and submits the token to the pods server for verification. // 3. verification passed The game server generates a cookie for the game client. // 4. the game client obtains the cookie of the game and communicates with the game server to ensure the security of identity authentication} @ Override public void onError (int returnCode, String info) {// do not call doLogin again here // a logon button should be left on the game interface to trigger doLogin login setText (R. id. account, "Logon Failed In Demo:" + MSG. trans (info); Log. e (TAG, MSG. trans (info) ;}}) ;}else if (R. id. logout_button = viewId) {Log. w (TAG, "doLogout! "); // DoLogout does not need to process the return method account. doLogout (getApplicationContext (), null); // Do the subsequent directly after doLogut was called. // I. e. finish your application. // Then when launching your app next time, user will see the login UI again .}}}
Final running effect:








Code: http://download.csdn.net/detail/my183100521/7138085


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.