123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526 |
- <?php
- namespace app\api\controller;
- use app\common\library\LianLianPay;
- use llianpay\accp\security\LLianPayAccpSignature;
- use think\Db;
- use llianpay\accp\client\LLianPayClient;
- date_default_timezone_set('Asia/Shanghai');
- header('Content-type:application/json;charset=utf-8');
- require_once env('root_path').'application/common/library/llp/src/cfg.php';
- require_once env('root_path').'application/common/library/llp/src/client/LLianPayClient.php';
- class CloudWallet extends Base
- {
- protected $env = 1;
- protected $prefix = 'xl_';
- protected static $domain_name = 'test';
- protected $cloud_url = [
-
- 'apply'=>[
- 'https://accpgw-ste.lianlianpay-inc.com/v1/acctmgr/openacct-apply',
- 'https://accpgw.lianlianpay.com/v1/acctmgr/openacct-apply',
- ],
-
- 'activate'=>[
- 'https://accpapi-ste.lianlianpay-inc.com/v1/acctmgr/openacct-activate-apply',
- 'https://accpapi.lianlianpay.com/v1/acctmgr/openacct-activate-apply',
- ],
-
- 'random'=>[
- 'https://accpapi-ste.lianlianpay-inc.com/v1/acctmgr/get-random',
- 'https://accpapi.lianlianpay.com/v1/acctmgr/get-random',
- ],
-
- 'userinfo'=>[
- 'https://accpapi-ste.lianlianpay-inc.com/v1/acctmgr/query-userinfo',
- 'https://accpapi.lianlianpay.com/v1/acctmgr/query-userinfo',
- ],
-
- 'acctinfo'=>[
- 'https://accpapi-ste.lianlianpay-inc.com/v1/acctmgr/query-acctinfo',
- 'https://accpapi.lianlianpay.com/v1/acctmgr/query-acctinfo',
- ],
-
- 'withdrawal'=>[
- 'https://accpapi-ste.lianlianpay-inc.com/v1/txn/withdrawal',
- 'https://accpapi.lianlianpay.com/v1/txn/withdrawal',
- ],
-
- 'validation'=>[
- 'https://accpapi-ste.lianlianpay-inc.com/v1/txn/validation-sms',
- 'https://accpapi.lianlianpay.com/v1/txn/validation-sms',
- ],
-
- 'cashier'=>[
- 'https://accpgw-ste.lianlianpay-inc.com/v1/cashier/paycreate',
- 'https://accpgw.lianlianpay.com/v1/cashier/paycreate',
- ],
- 'acctserial'=>[
- 'https://accpapi-ste.lianlianpay-inc.com/v1/acctmgr/query-acctserial',
- 'https://accpapi.lianlianpay.com/v1/acctmgr/query-acctserial',
- ],
- ];
- public function initialize(){
- $this->uid = input('user_id');
- parent::initialize();
-
- if(!checkAuth($this->uid))$this->error('暂未开放.....');
- }
-
- public function openAcctApply()
- {
- $user_id = $this->uid;
- $user_info = Db::name('store_member')->find($user_id);
-
- if(empty($user_info)) $this->error('用户信息有误');
- if(!$user_info['true_name'] || !$user_info['id_card']) $this->error('请先实名认证');
-
- $current = date("YmdHis");
- $params = [
- 'timestamp' => $current,
- 'oid_partner' => OID_PARTNER,
- 'user_id' => $this->prefix.$user_id,
- 'txn_seqno' => get_order_sn(),
- 'txn_time' =>$current,
- 'flag_chnl' => "H5",
- 'notify_url' => 'https://'.$_SERVER['HTTP_HOST'] . '/api/Notify/openAcctApplyNotify',
- 'user_type' => 'INNERUSER',
- 'basicInfo'=>[
- 'reg_phone' => $user_info['phone'] ,
- 'user_name' => $user_info['true_name'] ,
- 'id_type' => 'ID_CARD',
- 'id_no' => $user_info['id_card'] ,
- 'occupation' =>18,
- ],
- 'accountInfo' => [
- 'account_type' => 'PERSONAL_PAYMENT_ACCOUNT',
- 'account_need_level' => 'V3'
- ],
- 'linkedAcctInfo'=>[
-
-
- ],
- ];
-
- $url = $this->cloud_url['apply'][$this->env];
- $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
- $this->success('请求成功',json_decode($result,true));
- }
-
- public function activateApply()
- {
- $user_id = $this->uid;
- $password = input('post.password');
- $flag_chnl = input('get.flag_chnl','H5');
- $pkg_name = input('get.pkg_name');
- $app_name = input('get.app_name');
- $current = date("YmdHis");
- $rand_arr = self::getRandomKey($this->prefix.$user_id, $this->cloud_url['random'][$this->env],$flag_chnl,$pkg_name,$app_name);
- if($rand_arr['ret_code'] != '0000') $this->error($rand_arr['ret_msg']);
- $params = [
- 'timestamp' => $current,
- 'oid_partner' => OID_PARTNER,
- 'user_id' => $this->prefix.$user_id,
- 'txn_seqno' => get_order_sn(),
- 'txn_time' =>$current,
- 'notify_url' => 'https://'.$_SERVER['HTTP_HOST'] . '/api/Notify/openAcctApplyNotify',
- 'password' => $password,
- 'random_key' => $rand_arr['random_key'],
- 'accountInfo'=>[
- 'account_type' => 'PERSONAL_PAYMENT_ACCOUNT'
- ]
- ];
- $url = $this->cloud_url['activate'][$this->env];
- $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
- $this->success('请求成功',json_decode($result,true));
- }
-
- public function getRandomKeys()
- {
- $user_id = $this->uid;
- $flag_chnl = input('get.flag_chnl','H5');
- $pkg_name = input('get.pkg_name');
- $app_name = input('get.app_name');
- $res = self::getRandomKey($this->prefix.$user_id, $this->cloud_url['random'][$this->env],$flag_chnl,$pkg_name,$app_name);
- $this->success('请求成功',$res);
- }
-
- public static function getRandomKey($user_id,$url,$flag_chnl,$pkg_name,$app_name)
- {
- $current = date("YmdHis");
- $params = [
- 'timestamp' => $current,
- 'oid_partner' => OID_PARTNER,
- 'user_id' => $user_id,
- 'flag_chnl' => $flag_chnl,
- 'pkg_name' => $flag_chnl == 'H5' ? static::$domain_name :($pkg_name ? $pkg_name : 'test') ,
- 'app_name' => $flag_chnl == 'H5' ? static::$domain_name :($app_name ? $app_name : 'test') ,
- ];
-
- $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
- return json_decode($result,JSON_UNESCAPED_UNICODE);
- }
-
- public function getUserInfo()
- {
- $user_id = $this->uid;
- $current = date("YmdHis");
- $params = [
- 'timestamp' => $current,
- 'oid_partner' => OID_PARTNER,
- 'user_id' => $this->prefix.$user_id,
- ];
- $url = $url = $this->cloud_url['userinfo'][$this->env];
- $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
-
-
- $this->success('请求成功',json_decode($result,true));
- }
-
- public function getAcctInfo()
- {
- $user_id = $this->uid;
- $current = date("YmdHis");
- $params = [
- 'timestamp' => $current,
- 'oid_partner' => OID_PARTNER,
- 'user_id' => $this->prefix.$user_id,
- 'user_type' => 'INNERUSER',
- ];
- $url = $url = $this->cloud_url['acctinfo'][$this->env];
- $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
- $res = json_decode($result,true);
- if(isset($res['acctinfo_list'])) {
- $total_money = bcadd($res['acctinfo_list'][0]['amt_balcur'],$res['acctinfo_list'][1]['amt_balcur'],2);
- $total_balaval = bcadd($res['acctinfo_list'][0]['amt_balaval'],$res['acctinfo_list'][1]['amt_balaval'],2);
- $total_balfrz = bcadd($res['acctinfo_list'][0]['amt_balfrz'],$res['acctinfo_list'][1]['amt_balfrz'],2);
- }
- $res['total_money'] = !empty($total_money) ? $total_money : 0;
- $res['total_balaval'] = !empty($total_balaval) ? $total_balaval : 0;
- $res['total_balfrz'] = !empty($total_balfrz) ? $total_balfrz : 0;
- $this->success('请求成功',$res);
- }
-
- public function validationSms()
- {
- $user_id = $this->uid;
- $token = input('get.token');
- $txn_seqno = input('get.txn_seqno');
- $total_amount = input('get.total_amount');
- $verify_code = input('get.verify_code');
- $current = date("YmdHis");
- $params = [
- 'timestamp' => $current,
- 'oid_partner' => OID_PARTNER,
- 'payer_type'=>"USER",
- 'payer_id' => $this->prefix.$user_id,
- 'txn_seqno'=>$txn_seqno,
- 'total_amount'=>$total_amount,
- 'token'=>$token,
- 'verify_code'=>$verify_code
- ];
- $url = $this->cloud_url['validation'][$this->env];
- $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
- $this->success('请求成功',json_decode($result,true));
- }
-
- public function getAcctSerial()
- {
- $user_id = $this->uid;
- $current = date("YmdHis");
- $acct_type = input('acct_type','USEROWN_PSETTLE');
- $flag_dc = input('flag_dc','');
- $page_no = input('page',1);
- $page_size = input('page_num',10);
- $params = [
- 'timestamp' => $current,
- 'oid_partner' => OID_PARTNER,
- 'user_id' => $this->prefix.$user_id,
- 'user_type' => 'INNERUSER',
- 'acct_type' => $acct_type,
- 'date_start' => date("YmdHis",strtotime('-180 days')),
- 'date_end' => $current,
- 'flag_dc' => $flag_dc,
- 'page_no' => $page_no,
- 'page_size' => $page_size,
- ];
-
- $url = $url = $this->cloud_url['acctserial'][$this->env];
- $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
- $result = json_decode($result,true);
- if(!empty($result['acctbal_list']))
- {
- foreach ($result['acctbal_list'] as &$v) {
- $v['date_time'] = date('Y-m-d H:i:s',strtotime($v['txn_time']));
- }
- }
- $this->success('请求成功',$result);
- }
-
- public function cashierPay()
- {
- $voucher_order = [];
- $voucher_order['order_no'] = get_order_sn();
- $money = 10;
- $from = input('post.from',1);
- $user = Db::name('store_member')->where('id',$this->uid)->find();
- $notify_url = 'https://'.$_SERVER['HTTP_HOST'] . '/api/Pay/lianLianNotify';
- $return_url ='https://'.$_SERVER['HTTP_HOST']."/h5/pages/mine/mine";
- $risk_item= risk_item($user,'余额充值',$from == 1 ? 16 : 10);
- $res= LianLianPay::cashierPay($voucher_order['order_no'],$money,$this->uid,$notify_url,$return_url,'余额充值',[[
- 'payee_id'=>OID_PARTNER,
- 'payee_type' => 'MERCHANT',
- 'payee_amount' => $money,
- ]],$risk_item);
- $this->success('请求成功',$res);
- }
-
- public function withdrawal()
- {
- $user_id = $this->uid;
- $money = input('post.money');
- $password = input('post.password');
- $flag_chnl = input('get.flag_chnl','H5');
- $pkg_name = input('get.pkg_name');
- $app_name = input('get.app_name');
- $random_key = self::getRandomKey($this->prefix.$user_id, $this->cloud_url['random'][$this->env],$flag_chnl,$pkg_name,$app_name);
- $current = date("YmdHis");
- $user_info = Db::name('store_member')->where('id',$user_id)->find();
- $risk_item = risk_item($user_info,'余额提现',input('post,source',10));
- $notify_url = 'https://'.$_SERVER['HTTP_HOST'] . '/api/Pay/withdrawalNotify';
- $params = [
- 'timestamp' => $current,
- 'oid_partner' => OID_PARTNER,
- 'notify_url'=> $notify_url,
- 'risk_item'=>json_encode($risk_item),
- 'linked_acctno'=>$user_info['bank_num'],
- 'check_flag'=> 'N',
- 'pay_time_type'=> 'TRANS_NORMAL',
- 'orderInfo'=>[
- 'txn_seqno'=>get_order_sn(),
- 'txn_time' => $current,
- 'total_amount' => $money,
- ],
- 'payerInfo'=>[
- 'payer_type'=> 'USER',
- 'payer_id'=> $this->prefix.$user_id,
- 'payer_accttype'=> 'USEROWN',
- 'password'=> $password,
- 'random_key'=> $random_key['random_key'],
- ]
- ];
- $url = $url = $this->cloud_url['withdrawal'][$this->env];
- $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
- $this->success('请求成功',json_decode($result,true));
- }
- public function payNotifyTest()
- {
- $result = '{"oid_partner":"2020042200284052","payerInfo":[{"amount":"1.00","method":"BALANCE","payer_type":"USER","payer_id":"1"}],"txn_type":"GENERAL_CONSUME","payeeInfo":[{"amount":"1.00","payee_id":"2020042200284052","payee_type":"MERCHANT"}],"orderInfo":{"total_amount":"1.00","txn_seqno":"202210091020109197255438","txn_time":"20221009102010"},"txn_status":"TRADE_SUCCESS","accounting_date":"20221009","finish_time":"20221009102029","accp_txno":"2022100916760526"}';
- $header = '{"accept-encoding":"gzip,deflate","host":"xianglian-api.hdlkeji.com","content-length":"458","signature-type":"RSA","signature-data":"a5BMrkODcWl6FJ2vOEMG\/dnDbHfsBp34yY9ls9KmaWv5zYYO2EoK+DwL9PAFWTFzb0sKKYaOgrO8mFjl4CclTEd5UWvDFTAhv+EijImHTm4rGwbv1k2fpiw5MCSci1JTAE3ROsocgDWbLSsuFbTQ\/d97oR9KJbrjIInlVPEjO04=","correlationid":"2b9369df-ca95-49df-8f25-10fca9854c02","user-agent":"httpcomponents","connection":"Close","content-type":"text\/json;charset=UTF-8"}';
- $result = json_decode($result,true);
- $header = json_decode($header,true);
-
- $check_sign = LLianPayAccpSignature::checkSign(json_encode($result,JSON_UNESCAPED_UNICODE),$header['signature-data']);
- var_dump($check_sign);
- $orderNo = $result['orderInfo']['txn_seqno'];
- var_dump(['out_trade_no' => $orderNo,'user_id'=> trim($result['payerInfo'][0]['payer_id'],$this->prefix)]);
- }
- }
|