1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2018/12/12
- * Time: 11:13 AM
- */
- namespace openapi;
- //class config
- //{
- // const CONVERT_FCODE_API = "https://passport.lrlz.com/mobile/index.php";
- // const APP_ID = 'JYC_CHANNEL';
- // const APP_KEY = 'aa161e84685b42a6862dfa5552195240';
- // const RSA_PATH = BASE_ROOT_PATH . '/helper/openapi/keys/jyc_pri.pem';
- // const FCODE_FIELDS = ['appid','appkey','convert_sn','convert_type','batch_code','commonid','time','mobile','return_url'];
- //}
- class config
- {
- const CONVERT_URL = "https://passport.lrlz.com/mobile/index.php";
- const APP_ID = 'DHKJ_CHANNEL';
- const APP_KEY = '13e5b127aed296ef6d490cd7cc4c161e';
- const RSA_PATH = BASE_ROOT_PATH . '/helper/openapi/keys/dhkj_pri.pem';
- const FIELDS = ['appid','appkey','convert_sn','convert_type','time','mobile','return_url'];
- }
- class GoodsConvertor
- {
- static $pri_key = null;
- public function __construct()
- {
- if(self::$pri_key == null) {
- $pri_key = file_get_contents(config::RSA_PATH);
- self::$pri_key = openssl_get_privatekey($pri_key);
- }
- }
- public function fcode($params)
- {
- $body = $this->presign_body($params,config::FIELDS);
- $signed = $this->sign($body);
- $params['signed'] = $signed;
- $params['act'] = 'convert';
- $params['op'] = 'fcode';
- return config::CONVERT_URL . "?" . http_build_query($params);
- }
- public function user($params)
- {
- $body = $this->presign_body($params,config::FIELDS);
- $signed = $this->sign($body);
- $params['signed'] = $signed;
- $params['act'] = 'convert';
- $params['op'] = 'user';
- return config::CONVERT_URL . "?" . http_build_query($params);
- }
- private function sign($body)
- {
- openssl_sign($body, $signed, self::$pri_key);
- $signed = base64_encode($signed);
- return $signed;
- }
- private function presign_body($input,$fields)
- {
- ksort($input);
- reset($input);
- $params = [];
- foreach ($input as $key => $val)
- {
- if(in_array($key,$fields)) {
- $params[] = "{$key}={$val}";
- }
- }
- return implode('&',$params);
- }
- }
|