package com.lightinit.hsdataportal.common;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;

import java.io.FileWriter;
import java.io.IOException;

/**
 * @Author: sunxiang
 * @Date: 2018/10/26 21:17
 * @Description:
 **/
public class AlipayConfig {

    //TODO 代替换真实环境参数：URL,APP_ID,APP_PRIVATE_KEY,CHARSET,ALIPAY_PUBLIC_KEY,RETURN_URL.NOTIFY_URL,LOG_PATH
    public static String URL="https://openapi.alipaydev.com/gateway.do";
    public static String APP_ID="2016092000551385";
    public static String APP_PRIVATE_KEY="MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC8p7ndxfFbPj6/U0Rog0neVKapupW3ofZzhvLWuYhZU/mWatgjBD9pf96HYiwMV8VZZHQYvqswsjF1SSl3Ljt1E90CkBoA0Zvxeq94HUooHlzDITEM6Ki68ApZ1W7lrXHZ7DqDLSulI7DjPOQ3bKRxvqSyApaZf687GxG2LWmItzOoZrflT0OzqJCQtR1Up4k1UVaPW/b9LWOyGec7DDtiuwy8adT8Vs6FTg+f3djk7azAIDK69M5kIxBx0+1X2s1829ObDOBHwdGIbduMNUF5C+fzYxzSO8DaYzJukqMtI2Bj3l2I79YhtfXhYOZkGrZvPSKAp6CxKrsTrHtXI9YrAgMBAAECggEAP0iEMMCVleXrZoKoD+b6gHok7gqI7nCGG3rJOv5BnrVso+hzWEu0ec9K9l8YJ4vJx5LK3wIWqt8beBxyrGf1yfA/0vxDvMKTbQ2ajtBEb/C/bTVVHt9sukiLMFdIPANSjaeQeTBN07eFPrTOWUk4YG9zD8OOgS8zuL/70QCqxhEa7+5rkFm2uVtKwnCH9C9rVMVpx11X1eFHYFoQ7Uo2Iqls4Gu/I0kzSsn3w8Fft964ZkyLdTMow8wYbc5wuvDOwYB6+/4e/f37vxw569WYFBLXErS3rvoamxBgeZiL97WFVqL14X2IsN5K9LiIcSCNY6y7tkGCqzpvXSgI0i1uAQKBgQDedRwdyM1E0P/vXkgfAo0nXtbLDHYfmPka2qfCZvkDnu69Yd7FtdFLdkec87sUfreV8JyARardIT6nbwEJ27wtcDt3TYvXcCeLCU3AnxAwvVxcn8b8Y2Sgo9vY/u6MhZz09XXAg6I9GTRFBXxF8Gfl/3s6L+RjO3uLesFyE82/EwKBgQDZGdfiC04d9vGePghC1KAp5NEDWdM4DXXmcnHxUbWlispED1teGVXsp3b0MIBCDkmmN2wDrBUNUG/Rytk9jZ2UqDXT9aR+RHJ59Dnl6xnXPB4WQTamKnDpj9VILcQR/lTkxMNj9K5dPnUR5SsWdvKNUCbmC3wmNUCTj7PREAa3iQKBgAurfRQa6pnHlQWLnqDx01HTadUxDClQLxE3k0FhgYKtHb0Vm0gn55jb1ZnoN1I164+UFcGs5e+/xLen3RgVTOPdVWFG0iU1Hv3uOQP31DOaW3QIdbnbxPWgYvIZPY5lm/xFvC2jOimWXuWYChLpL6ojIuXEiWijQDHq+KbxXwO9AoGAIbMWRLtWg+Y6OUMNyznwJrCjFS8TT2cffwcS0s/JL4osvYXYu/GY2eRg3aTNs/M90XRW6vcCSY/L27fuItThuhqmSGGgCA2d63pSpnLpDvUBApla305FOqweAldAUT62dNBqOBDaJBU23PFCz/jky7S+ZQUxX0jy3jT3R6OCN2kCgYAd6HqRglp9jykxh/5DgUsK8kw4i5qLkbm9JcBijgbbPCeWPYdGDudDKxiz5t+Kd+Q4bvXdcSvFZOvMzoJYEwW7W+iLGWopLx6Q6Z7QH6A2mzNhuH5RcVPNhf3woLHZqZ1RmWTU7PMGokscKt7Vab3KVo30U5NUpaowZzYDhlgb4w==";
    public static String FORMAT="json";
    public static String CHARSET="utf-8";
    public static String ALIPAY_PUBLIC_KEY="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt9KgpPY/URzJg9TyRy/hO3m8mcwyRk4a2GvebuVhhLCd15bxgewtVhz6ajFB5y4vJ75x/TKfNsamc4A7pho8abKOrl2W6Ai28edNAssfMTilmpoycIXQwU7EgamHS0+t08iqeaJRwyrZFxb5MjEBeGtadCFOHRhl3r9E08iKPDx1cO7sAH5NmQKePGz321ld3SCFtHMo47ihaWmfuZx17VamlAr6NI/Qet5EhlP14k9/kWwzQ2Kgc1ZuRUovrQth/LcMuZnTYejlzBP5ipOc2jCcWq1sFptJ+jNfHp62mT7yt2A5PFd/Gz4nCpghMgd3G9T0U3WDzUrJfG7ptu2jhwIDAQAB";
    public static String SIGN_TYPE="RSA2";
    public static String RETURN_URL="http://localhost:8080/alipay/success.action";
    public static String NOTIFY_URL="http://localhost:8080/alipay/notice.action";
    //public static String RETURN_URL="http://aui64z.natappfree.cc/alipay/success.action";
    //public static String NOTIFY_URL="http://aui64z.natappfree.cc/alipay/notice.action";
    public static String LOG_PATH="c:\\";
    public static  AlipayClient getInstance(){
        return new DefaultAlipayClient(URL, APP_ID, APP_PRIVATE_KEY, FORMAT, CHARSET, ALIPAY_PUBLIC_KEY, SIGN_TYPE);
    }

    /**
     * 写日志，方便测试（看网站需求，也可以改成把记录存入数据库）
     * @param sWord 要写入日志里的文本内容
     */
    public static void logResult(String sWord) {
        FileWriter writer = null;
        try {
            writer = new FileWriter(LOG_PATH + "alipay_log_" + System.currentTimeMillis()+".txt");
            writer.write(sWord);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
