New Android Studio Imports micro-letter payment and Alipay official demo problem Solving Encyclopedia _android

Source: Internet
Author: User
Tags base64

Recent projects to use Alipay payment and micro-credit payment, I would like to use a Third-party payment framework ping++ or Beecloud, but because of their fees and charges, let me off, and the company gave the corresponding public key, private key and AppID, so the use of the open platform chant.

Go in for a long time to find a bunch of problems, oh, my God. Completely unintelligible, Baidu Google a heap, have not found enough solution. Well, here's the thing to share with you, if there are similar problems can be considered for use, the shortage of local Daniel do not spray.

Micro-letter Open platform has a document and SDK, you can go to see their own downloads, rockets: https://open.weixin.qq.com/

Alipay official demo and documentation is relatively simple, and more clearly said, rockets: https://open.alipay.com/platform/home.htm

Or first look at the running demo diagram:
The first is the micro-letter

And look at Alipay.

Click to pay will jump to your mobile phone Alipay app, if the phone does not download is also available, but not in a real Alipay app

But such a simple thing, the landlord is really IQ catch urgent, have been for half a day.

First is the introduction of micro-letter demo, to the official download of the Simpledemo, found a bunch of errors, well, first of all, the SDK, this is not more to repeat.

Then modify the try Again Oh,no, another ghost.


What ghost, look carefully, is drawable inside there is not a PNG file named PNG file.

Well, if you're patient enough, then dozens of pictures, you can still check the suffix directly, see if there is a PNG as a suffix, save it, or modify your filename to match the suffix name.

However, the programmer's ability should be reflected in the degree of laziness, so let me lazy.

Compilesdkversion
 buildtoolsversion "24.0.0"
 aaptoptions.cruncherenabled = False
 Aaptoptions.usenewcruncher = False

 defaultconfig {
  ApplicationID "Net.sourceforge.simcpux"
  Minsdkversion 4
  targetsdkversion
}

You only need to add two sentences to the corresponding Gradle file and the value to false.

Try again again, oh, no, this time is a lot of mistakes, what ghosts! Take a look at the log.

Oh, it was because of the official hidden HttpClient API after 6.0, but most of the imported code still uses this powerful framework.
Okay, just add one more word to the Gradle file.

 Android {
  uselibrary ' org.apache.http.legacy '
 }

dependencies {
 compile files (' libs/ Libammsdk.jar ')

 android {
  uselibrary ' org.apache.http.legacy '
 }
}

Another look at Alipay, it's much simpler. The first problem I encountered was not specifying APPID, the public key those things, OK, this is definitely going to have to get a series of things that you're applying for.
Run a look.


Hey, there is an interface, it should be OK, click to pay.

Oh on, direct crash


There's gotta be a reason to be wrong, look at the log.

null pointer exception? take a look.
sign = Urlencoder.encode (sign, "UTF-8");

There is a problem in such a sentence, what is the problem?

/**
  * Sign the order info. Sign information * * 
  @param content
  *   pending signed order information
 /private String sign ( String content) {return
  signutils.sign (content, rsa_private);
 }

The problem with this method, so the return is an empty one.
Let's go back in a look.

public static string sign (string content, String privatekey) {
  try {
   Pkcs8encodedkeyspec priPKCS8 = new Pkcs8encod Edkeyspec (
     base64.decode (Privatekey));
   Keyfactory KEYF = keyfactory.getinstance (algorithm);
   Privatekey Prikey = keyf.generateprivate (priPKCS8);

   Java.security.Signature Signature = Java.security.Signature
     . getinstance (SIGN_ALGORITHMS);

   Signature.initsign (Prikey);
   Signature.update (Content.getbytes (Default_charset));

   Byte[] signed = Signature.sign ();

   Return Base64.encode (Signed);
  } catch (Exception e) {
   e.printstacktrace ();
  }

  return null;
 }

Is such a string of code, the original method is to convert the private key to the format should be, and my company to change the views of the good, OK.
It's a straight back.

/**
  * Sign the order info. Sign information * * 
  @param content
  *   pending signed order information
 /private String sign ( String content) {
//return  signutils.sign (content, rsa_private);
  return rsa_private;
}

Modify it and run it again. Oh Yeah, success!
Today talk so much, what do not understand, or the use of universal Baidu it!

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.