<?php

/**
 * 应用宝 配置信息
 */
class config_for_yyb {

    const sandbox = false;

    /**
     * @var string cp在yyb后台注册的应用ID
     */
    public $appid;

    /**
     * @var string 与yyb约定的秘钥
     */
    public $appkey;

    /**
     * @var 米大师支付appid
     */
    public $pay_appid = '1112290006';                        # 米大师appid

    /**
     * @var 米大师支付appkey
     */
    public $pay_appkey;

    /**
     * @var string YSDK服务器地址
     */
    public $server_name;

    /**
     * @var string 沙箱测试
     */
    public $is_sandbox;

    /**
     * @var string 登录平台字符串qq或者wx
     */
    public $platStr_QQ_or_WX;

    /**
     * configs for yyb
     * @param string $plat qq or wx 由客户端传上来的参数决定
     * @param boolean $sandbox 同样由客户端传参
     *  @return config_for_yyb Description
     */
    static function Inst($plat) {
        $cfg = new config_for_yyb();
        $cfg->platStr_QQ_or_WX = $plat;
        if (strtolower($plat) == "qq") {                                        # 手Q
            $cfg->appid = "1112290006";
            $cfg->appkey = 'oxr1ig9rnd52iFHm';                                  # 手QAppkey
        } else {                                                                # 微信
            $cfg->appid = 'wx0377dfa35b5877f5';
            $cfg->appkey = '918a02a62aefb1903fa423b68f74d700';                  # 微信Appkey
        }
        if (self::sandbox) {                                                    # 沙箱测试
            $cfg->server_name = 'ysdktest.qq.com';
            $cfg->pay_appkey = 'oxr1ig9rnd52iFHm';                              # 米大师沙箱AppKey
        } else {                                                                # 正式版
            $cfg->server_name = 'ysdk.qq.com';
            $cfg->pay_appkey = '5myPFhN44yF9wnOvylCwTQzSwtLqoAWe';              # 米大师现网AppKey
        }
        return $cfg;
    }

    /**
     * cee付费sig校验流程
     * @param type $params
     * @return type
     */
    function cee_verify_sig($method, $params, $url_path, &$sig_new) {
        // 获取原sig
        $sig = urldecode($params['sig']);
        $secret = $this->appkey . '&';
        return SnsSigCheck::verifySig($method, $url_path, $params, $secret, $sig, $sig_new);
    }

    /**
     * PS. 仅限pay.php作为入口使用才行
     * @return string 获取支付回调地址,
     */
    public function get_notify_url() {
        $url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"];
        switch ($this->getPlatStr()) {
            case "hykb":
                $nurl = substr($url, 0, strpos($url, "pay.php")) . "notify_hykb.php";
                break;
            default:
                $nurl = substr($url, 0, strpos($url, "pay.php")) . "notify.php";
                break;
        }
        return $nurl;                                                           # 回调地址
    }

}
