package com.wechat.config;

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

import com.wechat.common.utils.BaseUtils;

/* *
 *类名：AlipayConfig
 *功能：基础配置类
 *详细：设置帐户有关信息及返回路径
 *修改日期：2017-04-05
 *说明：
 *以下代码只是为了方便商户测试而提供的样例代码，商户可以根据自己网站的需要，按照技术文档编写,并非一定要使用该代码。
 *该代码仅供学习和研究支付宝接口使用，只是提供一个参考。
 */
@Component
public class AlipayConfig {

    // ↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

    // 应用ID,您的APPID，收款账号既是您的APPID对应支付宝账号
    public static String app_id = "2016091400511497";

    // 商户私钥，您的PKCS8格式RSA2私钥
    public static String merchant_private_key = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCrleqPtDAdqzBXLG3+5abMuGR8FslRaqxMHxcuZYsz3V/CWlTSITou3UHm+OlNlHK2GlpXOLW0soSqJKymDIloMgZC/fVBHhItAkupEHgEltn4P8QCqY9RLMp9eQW5bxkxt5oedJJH43CAImiIUubLhwDb1QdOYHYibD6ttVOF7tSjwpI2FZiWgKOMbtkBKBh2Xe3ML/Pr6MZRICG3a8B2/VdtT8kGj4RGXRnNj7ClhA5Fnf8svB2WIffxKU60RhM390mjMh3qGb8bLn+UOtDgy1Jj9Tbp3xMUid6rZxERK1A5qEpxB9VV0K24a6yzjLNhMiw+6l4ufkQwOguBu3cBAgMBAAECggEAXjglJCHqpfABzGyOPgC3FgVO0EDm7TkpQWd1IDoMNT+jPKLDnts2CtPeQ0l9OueAEfTolKqERKQeaxtWXpvVvAx0GcdALDCqBGMVTtHHRaXcLRA+vsOC+i0hR8Lz3L5f1EggbgbO6IDAnuvGAM2dBDeuxgf1Shl35TERPeuq4Ii78hj2qN7sbp3OJH4rNCvfiqicrgCdmk/Qo8oVSkizoDqKoEMW4t8RaChoWphGeqFYkFsl21CbxH47WGXLMZUZFocBlQhpl53DY52GMw3DwtTz1wJcZUmtY0L1yUKDyjEfix8dWWQdy4YVsDc7TCS2jYmuXUK5CS2la90zI93nPQKBgQDtRtCOyCcZlAZXu79WJKNLpiutTUjhwGHhagcNEUhwiPdIHG6qPUe2Y2cxGGKDDE/GvwTL5ppR64CbwbTOH+CKUgEonPi2h4rB+HTGvFwqH5eZY+It81CJArqF5c1BImlIasUONigW3iv3iRnCCBDLrrCetd+ACG5hX8CD5DquQwKBgQC5IBamjBqMiw0z1TUqR4lRvFdGtz97i6TdSz09Knd3uzdxq8tSqNQFH2gmrMrGKLsnRHF52kOT7hxV3v3DfP9mHXRf7FZsV9B6MQKnHnOxAFLiBnCOQS+Wlw+Y4PjdaHWaXpuVO5UBoVLEhh1UJho44HdEZmXxLbCvvAhfVk1LawKBgQCC2w4D4HBn09HXqqwv5s7D1qW50qiCD+YrOZ0f4MsxfOfbNgr2Cgu1k4aCde9GVJDei9QqW0f6K8XmoGKFVuEvh2AqNL+ZcpDcvpgwTgsKFBg4OPSw4MImfYG+fGjBJigoDvIUD1v2mJpozoyNDIOuwO2Y6baT1pKBUxxJ4KFYHwKBgH+vJDBHHeCl37tKaNr6cDoR31iE96Is1M9VH63aZoAMftdGGHywuVu3J8zVDR7T5RHWYTYcVtPnPV/05643vqgd1LB8f7dGciJ1P1Eo7b69bG0859EWIM6K7lURhlSfwc1xR3oMmF+Bd2bY4c2yYg+sslZZEiLg0qbC2Dt5eOJ1AoGBAMePw9HuHxPwyxzxl9NSnxGWWlOTKGAn1TizqMB/rAeFmBL5HM9ZtptGPBCKs/K1zL2YnUeDJeP9DZQIHME98w6FnTy4xqCO8QvyBJ8RlWj2jVBxmP+ASidvtKFHc63PepmVpoq+4sSHSjLBVVf8kIBCur+GnrtIctZoYjzac3fG";

    // 支付宝公钥,查看地址：https://openhome.alipay.com/platform/keyManage.htm
    // 对应APPID下的支付宝公钥。
    public static String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA43S8BUhcInAPPfu/WYsvh3pR1bfy+MuP/23mXJfvlD8MH6JQnV3b17yx82wUdsIr6I4xkybMTgftPGkUWzDEpwTt0nP4j5RupBBNp9tN2P7DUPLpBrz80PbIi80P+/ATFyhK86IUZ5Nc1e9XTIrVD9PuDMHK4SDKofMMxfYkoGMPdWzh5QhXT8IM8RqqCrdwvwchNGxVFjCJCEtH/3s0hHza6tFWHbchS1V5KqFN0v0ND47vg4hIpzrRucAFfqlRFbVTPFSKkUlMZRvyWNed46Wr9vbNhgOsp8TYpgrNMIUnWjklklxzaQDtRUytDDEY6D5BQx7lRNk/emexSMtVnQIDAQAB";

    // 服务器异步通知页面路径 需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
    public static String notify_url = "http://localhost:8080/RecruitmentApi/Order/aliPay_notify_url";

    // 页面跳转同步通知页面路径 需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
    public static String return_url = "http://localhost:8080/RecruitmentApi/Order/notify_url";

    // 签名方式
    public static String sign_type = "RSA2";

    // 字符编码格式
    public static String charset = "utf-8";

    // 支付宝网关
    public static String gatewayUrl = "https://openapi.alipaydev.com/gateway.do";

    // 支付宝网关
    public static String log_path = "C:\\";

    // ↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

    protected static final Log log = LogFactory.getLog(AlipayConfig.class);
    
    /**
     * 写日志，方便测试（看网站需求，也可以改成把记录存入数据库）
     * 
     * @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) {
        	log.error(e);
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException e) {
                	log.error("支付宝异常",e);
                }
            }
        }
    }
}
