<?php

/**
 * Description of config_vivo
 * @version
 *          1.0.0 Created at 2018-3-3. by --gwang
 * @author gwang (mail@wanggangzero.cn)
 * @copyright ? 2018-3-3, SJZ LoyalSoft Corporation & gwang. All rights reserved.
 */
class config_vivo
{

    /**
     * @var string 验证登录token接口 URI
     */
    public $vivo_api_login = 'https://usrsys.vivo.com.cn/sdk/user/auth.do';

    /**
     * @var string vivo后台创建订单接口 URI
     */
    public $vivo_api_trade = 'https://pay.vivo.com.cn/vcoin/trade';

    /**
     *
     * @var string vivo 后台查询订单接口 URI
     */
    public $vivo_api_query = 'https://pay.vivo.com.cn/vcoin/queryv2';
//put your code here
    /**
     * @var string vivo 后台应用ID
     */
    public $appId = '192d8d04de7c503bbada5e696f4e953a';

    /**
     * @var string vivo 后台开发商ID
     */
    public $cpId = 'a8f45473e4699ba87f96';

    /**
     * @var string vivo 后台应用 appkey
     */
    public $appKey = '3a1090587b91686582f5e3e6ecfe58b0';

    /**
     *
     * @return \config_vivo
     */
    static public function Inst()
    {
        return new config_vivo();
    }

    /**
     * vivo 签名算法
     * @param type $params
     * @param type $appkey
     * @return type
     */
    function vivo_sign($params)                                                # vivo签名算法
    {
        unset($params['signMethod']);
        unset($params['signature']);
        ksort($params);                                                         # 除sign以外的所有字段, 字典排序
        $arr = array();
        foreach ($params as $key => $val) {
            array_push($arr, $key . '=' . urldecode($val));                     # 排序后的数组, 需要对value进行urldecode
        }
        $arr[] = strtolower(md5($this->appKey));                                # 加上appkey
        $query_string = join('&', $arr);                                        # 重新拼接为字符串
        return strtolower(md5($query_string));                                  # 取md5值
    }

}
