Android reward function: Alipay transfer

It is suitable for individual developers to develop APP, allowing users to reward the author, in essence, to transfer Alipay accounts to designated accounts.

First, open the Alipay APP, click the "collection" function, save the payroll code (Er Weima) picture to the mobile phone (further move to the computer).

2. Find an online QR code analysis website tool to analyze the payment code picture. Copy the last / following string, which is the part to be used

3. Add a tool class as follows

public class AlipayUtil {
    // Alipay package name
    private static final String ALIPAY_PACKAGE_NAME = "com.eg.android.AlipayGphone";

    // Old Alipay 2D code universal Intent Scheme Url format
    private static final String INTENT_URL_FORMAT = "intent://platformapi/startapp?saId=10000007&" +
            "clientVersion=3.7.0.0718&qrcode=https%3A%2F%2Fqr.alipay.com%2F{urlCode}%3F_s" +
            "%3Dweb-other&_t=1472443966571#Intent;" +
            "scheme=alipayqr;package=com.eg.android.AlipayGphone;end";

    /**
     * Open transfer window
     * The old Alipay two-dimensional code method needs to be used. https://fama.alipay.com/qrcode/index.htm Website generated QR code
     * This method is the best, but in August 2016, it was found that new users may not be able to use it
     *
     * @param activity Parent Activity
     * @param urlCode  Manually parse the QR code to obtain the parameters in the address, for example https://qr.alipay.com/aehvyvf4taua18zo6e The last one
     * @return Call succeeded or not
     */
    public static boolean startAlipayClient(Activity activity, String urlCode) {
        return startIntentUrl(activity, INTENT_URL_FORMAT.replace("{urlCode}", urlCode));
    }

    /**
     * Open Intent Scheme Url
     *
     * @param activity      Parent Activity
     * @param intentFullUrl Intent Jump address
     * @return Call succeeded or not
     */
    public static boolean startIntentUrl(Activity activity, String intentFullUrl) {
        try {
            Intent intent = Intent.parseUri(
                    intentFullUrl,
                    Intent.URI_INTENT_SCHEME
            );
            activity.startActivity(intent);
            return true;
        } catch (URISyntaxException e) {
            e.printStackTrace();
            return false;
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * To determine whether the Alipay client has been installed, it is recommended to call the check before transfer.
     *
     * @param context Context
     * @return Is Alipay client installed?
     */
    public static boolean hasInstalledAlipayClient(Context context) {
        PackageManager pm = context.getPackageManager();
        try {
            PackageInfo info = pm.getPackageInfo(ALIPAY_PACKAGE_NAME, 0);
            return info != null;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return false;
        }
    }
}

  

Four, the call method, the second part of the string to achieve the user can open to the designated Alipay account transfer interface.

          if (AlipayUtil.hasInstalledAlipayClient(this)){
                    AlipayUtil.startAlipayClient(this,"XXXXXXXXXXXXXXXX"); // String obtained in step 2
                }else{
                    TastyToast.makeText(this, "Alipay is not detected, and no reward function can be achieved.", TastyToast.LENGTH_SHORT, TastyToast.CONFUSING);
                }

Tags: Android QRCode Mobile

Posted on Sun, 03 May 2020 16:35:33 -0400 by sergio-pro