CloudWallet.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\library\LianLianPay;
  4. use llianpay\accp\security\LLianPayAccpSignature;
  5. use think\Db;
  6. use llianpay\accp\client\LLianPayClient;
  7. date_default_timezone_set('Asia/Shanghai');
  8. header('Content-type:application/json;charset=utf-8');
  9. require_once env('root_path').'application/common/library/llp/src/cfg.php';
  10. require_once env('root_path').'application/common/library/llp/src/client/LLianPayClient.php';
  11. /**
  12. * @title 云钱包【提现、充值和支付还是用之前接接口】
  13. * @desc 用的是测试环境的用户钱包,测试环境忽略user_id不同接口结果不一致的场景
  14. * @controller CloudWallet
  15. * @package app\api\controller
  16. * @group worker
  17. */
  18. class CloudWallet extends Base
  19. {
  20. protected $env = 0; // 0 测试环境 1正式环境
  21. protected $prefix = 'xl_';
  22. protected static $domain_name = 'test';
  23. protected $cloud_url = [
  24. //用户申请接入[云钱包申请开户]
  25. 'apply'=>[
  26. 'https://accpgw-ste.lianlianpay-inc.com/v1/acctmgr/openacct-apply',//测试环境
  27. 'https://accpgw.lianlianpay.com/v1/acctmgr/openacct-apply',//生产环境
  28. ],
  29. // 激活云钱包
  30. 'activate'=>[
  31. 'https://accpapi-ste.lianlianpay-inc.com/v1/acctmgr/openacct-activate-apply',//测试环境
  32. 'https://accpapi.lianlianpay.com/v1/acctmgr/openacct-activate-apply',//生产环境
  33. ],
  34. // 随机因子
  35. 'random'=>[
  36. 'https://accpapi-ste.lianlianpay-inc.com/v1/acctmgr/get-random',//测试环境
  37. 'https://accpapi.lianlianpay.com/v1/acctmgr/get-random',//生产环境
  38. ],
  39. // 获取云钱包用户信息
  40. 'userinfo'=>[
  41. 'https://accpapi-ste.lianlianpay-inc.com/v1/acctmgr/query-userinfo',//测试环境
  42. 'https://accpapi.lianlianpay.com/v1/acctmgr/query-userinfo',//生产环境
  43. ],
  44. // 获取云钱包账号信息
  45. 'acctinfo'=>[
  46. 'https://accpapi-ste.lianlianpay-inc.com/v1/acctmgr/query-acctinfo',//测试环境
  47. 'https://accpapi.lianlianpay.com/v1/acctmgr/query-acctinfo',//生产环境
  48. ],
  49. // 云钱包提现
  50. 'withdrawal'=>[
  51. 'https://accpapi-ste.lianlianpay-inc.com/v1/txn/withdrawal',//测试环境
  52. 'https://accpapi.lianlianpay.com/v1/txn/withdrawal',//生产环境
  53. ],
  54. //交易二次短信验证
  55. 'validation'=>[
  56. 'https://accpapi-ste.lianlianpay-inc.com/v1/txn/validation-sms',//测试环境
  57. 'https://accpapi.lianlianpay.com/v1/txn/validation-sms',//生产环境
  58. ],
  59. // 支付
  60. 'cashier'=>[
  61. 'https://accpgw-ste.lianlianpay-inc.com/v1/cashier/paycreate',//测试环境
  62. 'https://accpgw.lianlianpay.com/v1/cashier/paycreate',//生产环境
  63. ],
  64. ];
  65. public function initialize(){
  66. parent::initialize();
  67. //parent::check_login();
  68. }
  69. /**
  70. * @title 申请接入[开户]
  71. * @desc 申请接入[开户]
  72. * @author qc
  73. * @method POST
  74. * @tag 编辑信息
  75. * @url /api/Cloud_wallet/openAcctApply
  76. * @header name:Authorization require:1 desc:Token
  77. * @param name:user_id type:int require:0 default:0 desc:用户id
  78. * @return name:ret_code type:string default:0 desc:0000:成功,其他异常
  79. * @return name:ret_msg type:string default:0 desc:请求结果描述
  80. * @return name:user_status type:string default:0 desc:用户状态【NORMAL:正常,其他异常】
  81. * @return name:bank_open_flag type:int default:0 desc:银行开户标识【0未开户,1已开户,2开户中】
  82. * @return name:bank_account type:string default:0 desc:ACCP合作银行账户
  83. */
  84. public function openAcctApply()
  85. {
  86. $user_id = input('post.user_id');
  87. $user_info = Db::name('store_member')->find($user_id);
  88. //if(empty($user_info)) $user_info = Db::name('store_member')->find(6);
  89. if(empty($user_info)) $this->error('用户信息有误');
  90. if(!$user_info['true_name'] || !$user_info['id_card']) $this->error('请先实名认证');
  91. //if(!$user_info['bank_num']) $this->error('请绑定银行卡');
  92. $current = date("YmdHis");
  93. $params = [
  94. 'timestamp' => $current,
  95. 'oid_partner' => OID_PARTNER,
  96. 'user_id' => $this->prefix.$user_id,
  97. 'txn_seqno' => get_order_sn(),
  98. 'txn_time' =>$current,
  99. 'flag_chnl' => "H5",
  100. 'notify_url' => 'https://'.$_SERVER['HTTP_HOST'] . '/api/Notify/openAcctApplyNotify',
  101. 'user_type' => 'INNERUSER',
  102. 'basicInfo'=>[
  103. 'reg_phone' => $user_info['phone'] ,
  104. 'user_name' => $user_info['true_name'] ,
  105. 'id_type' => 'ID_CARD',
  106. 'id_no' => $user_info['id_card'] ,
  107. 'occupation' =>18,
  108. ],
  109. 'accountInfo' => [
  110. //'account_type' => 'PERSONAL_PAYMENT_ACCOUNT'
  111. ],
  112. 'linkedAcctInfo'=>[
  113. //'linked_accttype'=> 'LEGALREPT_BANK_CARD',
  114. //'linked_acctno'=> $user_info['bank_num'] ,
  115. ],
  116. ];
  117. $url = $this->cloud_url['apply'][$this->env];
  118. $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
  119. $this->success('ok',json_decode($result,true));
  120. }
  121. /**
  122. * @title 激活申请
  123. * @desc 激活申请
  124. * @author qc
  125. * @method POST
  126. * @tag 编辑信息
  127. * @url /api/Cloud_wallet/activateApply
  128. * @header name:Authorization require:1 desc:Token
  129. * @param name:user_id type:int require:0 default:0 desc:用户id
  130. * @param name:password type:string require:0 default:0 desc:支付密码。6-12位的字母、数字,不可以是连续或者重复的数字和字母,正则:^[a-zA-Z0-9]{6,12}$。通过密码控件加密成密文传输
  131. * @param name:pkg_name type:string require:0 default:test desc:APP包名[h5或是测试不用传]
  132. * @param name:app_name type:string require:0 default:test desc:APP应用名[h5或是测试不用传]
  133. * @param name:flag_chnl type:string require:0 default:H5 desc:交易发起渠道传H5或APP
  134. * @return name:ret_code type:string default:0 desc:0000:成功,其他异常
  135. * @return name:ret_msg type:string default:0 desc:请求结果描述
  136. * @return name:user_status type:string default:0 desc:用户状态【NORMAL:正常,其他异常】
  137. * @return name:bank_open_flag type:int default:0 desc:银行开户标识【0未开户,1已开户,2开户中】
  138. * @return name:bank_account type:string default:0 desc:ACCP合作银行账户
  139. */
  140. public function activateApply()
  141. {
  142. $user_id = input('post.user_id');
  143. $password = input('post.password');
  144. $flag_chnl = input('get.flag_chnl','H5');
  145. $pkg_name = input('get.pkg_name');
  146. $app_name = input('get.app_name');
  147. $current = date("YmdHis");
  148. $rand_arr = self::getRandomKey($this->prefix.$user_id, $this->cloud_url['random'][$this->env],$flag_chnl,$pkg_name,$app_name);
  149. if($rand_arr['ret_code'] != '0000') $this->error($rand_arr['ret_msg']);
  150. $params = [
  151. 'timestamp' => $current,
  152. 'oid_partner' => OID_PARTNER,
  153. 'user_id' => $this->prefix.$user_id,
  154. 'txn_seqno' => get_order_sn(),
  155. 'txn_time' =>$current,
  156. 'notify_url' => 'https://'.$_SERVER['HTTP_HOST'] . '/api/Notify/openAcctApplyNotify',
  157. 'password' => $password,
  158. 'random_key' => $rand_arr['random_key'],
  159. 'accountInfo'=>[
  160. //'account_type' => 'PERSONAL_PAYMENT_ACCOUNT'
  161. ]
  162. ];
  163. $url = $this->cloud_url['activate'][$this->env];
  164. $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
  165. $this->success('ok',json_decode($result,true));
  166. }
  167. /**
  168. * @title 获取随机因子
  169. * @desc 获取随机因子
  170. * @author qc
  171. * @method GET
  172. * @tag 编辑信息
  173. * @url /api/Cloud_wallet/getRandomKeys
  174. * @header name:Authorization require:1 desc:Token
  175. * @param name:user_id type:int require:0 default:0 desc:用户id
  176. * @param name:pkg_name type:string require:0 default:test desc:APP包名[h5或是测试不用传]
  177. * @param name:app_name type:string require:0 default:test desc:APP应用名[h5或是测试不用传]
  178. * @param name:flag_chnl type:string require:0 default:H5 desc:交易发起渠道传H5或APP
  179. * @return name:ret_code type:string default:0 desc:0000:成功,其他异常
  180. * @return name:ret_msg type:string default:0 desc:请求结果描述
  181. * @return name:random_key type:string default:0 desc:随机因子key,有效期30分钟
  182. * @return name:random_value type:string default:0 desc:随机因子值,有效期30分钟
  183. */
  184. public function getRandomKeys()
  185. {
  186. $user_id = input('get.user_id');
  187. $flag_chnl = input('get.flag_chnl','H5');
  188. $pkg_name = input('get.pkg_name');
  189. $app_name = input('get.app_name');
  190. $res = self::getRandomKey($this->prefix.$user_id, $this->cloud_url['random'][$this->env],$flag_chnl,$pkg_name,$app_name);
  191. $this->success('ok',$res);
  192. }
  193. // 获取随机因子
  194. public static function getRandomKey($user_id,$url,$flag_chnl,$pkg_name,$app_name)
  195. {
  196. $current = date("YmdHis");
  197. $params = [
  198. 'timestamp' => $current,
  199. 'oid_partner' => OID_PARTNER,
  200. 'user_id' => $user_id,
  201. 'flag_chnl' => $flag_chnl,
  202. 'pkg_name' => $flag_chnl == 'H5' ? static::$domain_name :($pkg_name ? $pkg_name : 'test') ,
  203. 'app_name' => $flag_chnl == 'H5' ? static::$domain_name :($app_name ? $app_name : 'test') ,
  204. ];
  205. //var_dump($params);
  206. $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
  207. return json_decode($result,JSON_UNESCAPED_UNICODE);
  208. }
  209. /**
  210. * @title 获取云钱包用户信息
  211. * @desc 获取云钱包用户信息
  212. * @author qc
  213. * @method GET
  214. * @tag 编辑信息
  215. * @url /api/Cloud_wallet/getUserInfo
  216. * @header name:Authorization require:1 desc:Token
  217. * @param name:user_id type:int require:0 default:0 desc:用户id
  218. * @return name:ret_code type:string default:0 desc:0000:成功,其他异常
  219. * @return name:ret_msg type:string default:0 desc:请求结果描述
  220. * @return name:user_status type:string default:0 desc:用户状态【NORMAL:正常,其他异常】
  221. * @return name:bank_open_flag type:int default:0 desc:银行开户标识【0未开户,1已开户,2开户中】
  222. * @return name:bank_account type:string default:0 desc:ACCP合作银行账户
  223. */
  224. public function getUserInfo()
  225. {
  226. $user_id = input('get.user_id');
  227. $current = date("YmdHis");
  228. $params = [
  229. 'timestamp' => $current,
  230. 'oid_partner' => OID_PARTNER,
  231. 'user_id' => $this->prefix.$user_id,
  232. ];
  233. $url = $url = $this->cloud_url['userinfo'][$this->env];
  234. $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
  235. $this->success('ok',json_decode($result,true));
  236. }
  237. /**
  238. * @title 获取云钱包账户信息
  239. * @desc 获取云钱包账户信息
  240. * @author qc
  241. * @method GET
  242. * @tag 编辑信息
  243. * @url /api/Cloud_wallet/getAcctInfo
  244. * @header name:Authorization require:1 desc:Token
  245. * @param name:user_id type:int require:0 default:0 desc:用户id
  246. * @return name:ret_code type:string default:0 desc:0000:成功,其他异常
  247. * @return name:ret_msg type:string default:0 desc:请求结果描述
  248. * @return name:ret_msg type:string default:0 desc:请求结果描述
  249. * @return name:acctinfo_list type:array default:0 desc:账户列表
  250. * @return name:acctinfo_list.oid_acctno type:string default:0 desc:账户号
  251. * @return name:acctinfo_list.acct_state type:string default:0 desc:账户状态【NORMAL:正常,其他异常】
  252. * @return name:acctinfo_list.amt_balcur type:float default:0 desc:资金余额[单位:元]
  253. * @return name:acctinfo_list.amt_balaval type:float default:0 desc:可用余额[单位:元]
  254. * @return name:acctinfo_list.amt_balfrz type:float default:0 desc:冻结金额[单位:元]
  255. * @return name:acctinfo_list.amt_lastbal type:float default:0 desc:昨日资金余额[单位:元]
  256. * @return name:acctinfo_list.amt_lastaval type:float default:0 desc:昨日可用余额[单位:元]
  257. * @return name:acctinfo_list.amt_lastfrz type:float default:0 desc:昨日冻结金额[单位:元]
  258. *
  259. */
  260. public function getAcctInfo()
  261. {
  262. $user_id = input('get.user_id');
  263. $current = date("YmdHis");
  264. $params = [
  265. 'timestamp' => $current,
  266. 'oid_partner' => OID_PARTNER,
  267. 'user_id' => $this->prefix.$user_id,
  268. 'user_type' => 'INNERUSER',
  269. ];
  270. $url = $url = $this->cloud_url['acctinfo'][$this->env];
  271. $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
  272. $this->success('ok',json_decode($result,true));
  273. }
  274. /**
  275. * @title 交易二次短信验证
  276. * @desc 交易二次短信验证
  277. * @author qc
  278. * @method GET
  279. * @tag 编辑信息
  280. * @url /api/Cloud_wallet/validationSms
  281. * @header name:Authorization require:1 desc:Token
  282. * @param name:user_id type:int require:0 default:0 desc:用户id
  283. * @param name:txn_seqno type:int require:0 default:0 desc:订单号
  284. * @param name:total_amount type:int require:0 default:0 desc:订单金额【提现金额】
  285. * @param name:token type:int require:0 default:0 desc:token
  286. * @param name:verify_code type:int require:0 default:0 desc:验证码
  287. * @return name:ret_code type:string default:0 desc:0000:成功,其他异常
  288. * @return name:ret_msg type:string default:0 desc:请求结果描述
  289. */
  290. public function validationSms()
  291. {
  292. $user_id = input('get.user_id');
  293. $token = input('get.token');
  294. $txn_seqno = input('get.txn_seqno');
  295. $total_amount = input('get.total_amount');
  296. $verify_code = input('get.verify_code');
  297. $current = date("YmdHis");
  298. $params = [
  299. 'timestamp' => $current,
  300. 'oid_partner' => OID_PARTNER,
  301. 'payer_type'=>"USER",
  302. 'payer_id' => $this->prefix.$user_id,
  303. 'txn_seqno'=>$txn_seqno,
  304. 'total_amount'=>$total_amount,
  305. 'token'=>$token,
  306. 'verify_code'=>$verify_code
  307. ];
  308. $url = $this->cloud_url['validation'][$this->env];
  309. $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
  310. $this->success('ok',json_decode($result,true));
  311. }
  312. /**
  313. * @title 收银台支付测试【测试用不对接】
  314. * @desc 收银台支付测试
  315. * @author qc
  316. * @method GET
  317. * @tag 编辑信息
  318. * @url /api/Cloud_wallet/cashierPay
  319. */
  320. public function cashierPay()
  321. {
  322. $voucher_order = [];
  323. $voucher_order['order_no'] = get_order_sn();
  324. $money = 10;
  325. $from = input('post.from',1);
  326. $user = Db::name('store_member')->where('id',$this->uid)->find();
  327. $notify_url = 'https://'.$_SERVER['HTTP_HOST'] . '/api/Pay/lianLianNotify';
  328. $return_url ='https://'.$_SERVER['HTTP_HOST']."/h5/pages/mine/mine";//回调地址
  329. $risk_item= risk_item($user,'余额充值',$from == 1 ? 16 : 10);
  330. $res= LianLianPay::cashierPay($voucher_order['order_no'],$money,$this->uid,$notify_url,$return_url,'余额充值',[[
  331. 'payee_id'=>OID_PARTNER,
  332. 'payee_type' => 'MERCHANT',
  333. 'payee_amount' => $money,
  334. ]],$risk_item);
  335. $this->success('ok',$res);
  336. }
  337. /**
  338. * @title 云钱包提现【测试用不对接】
  339. * @desc 云钱包提现
  340. * @author qc
  341. * @method POST
  342. * @tag 编辑信息
  343. * @url /api/Cloud_wallet/withdrawal
  344. * @header name:Authorization require:1 desc:Token
  345. * @param name:user_id type:int require:0 default:0 desc:用户id
  346. * @param name:source type:int require:0 default:10 desc:app传10,h5传16
  347. * @param name:pkg_name type:string require:0 default:test desc:APP包名[h5或是测试不用传]
  348. * @param name:app_name type:string require:0 default:test desc:APP应用名[h5或是测试不用传]
  349. * @param name:flag_chnl type:string require:0 default:H5 desc:交易发起渠道传H5或ANDROID或IOS
  350. * @return name:ret_code type:string default:0 desc:0000:成功,其他异常
  351. * @return name:ret_msg type:string default:0 desc:请求结果描述
  352. */
  353. public function withdrawal()
  354. {
  355. $user_id = input('post.user_id');
  356. $money = input('post.money');
  357. $password = input('post.password');
  358. $flag_chnl = input('get.flag_chnl','H5');
  359. $pkg_name = input('get.pkg_name');
  360. $app_name = input('get.app_name');
  361. $random_key = self::getRandomKey($this->prefix.$user_id, $this->cloud_url['random'][$this->env],$flag_chnl,$pkg_name,$app_name);
  362. $current = date("YmdHis");
  363. $user_info = Db::name('store_member')->where('id',$user_id)->find();
  364. $risk_item = risk_item($user_info,'余额提现',input('post,source',10));
  365. $notify_url = 'https://'.$_SERVER['HTTP_HOST'] . '/api/Pay/withdrawalNotify';
  366. $params = [
  367. 'timestamp' => $current,
  368. 'oid_partner' => OID_PARTNER,
  369. 'notify_url'=> $notify_url,
  370. 'risk_item'=>json_encode($risk_item),
  371. 'linked_acctno'=>$user_info['bank_num'],
  372. 'check_flag'=> 'N',
  373. 'pay_time_type'=> 'TRANS_NORMAL',
  374. 'orderInfo'=>[
  375. 'txn_seqno'=>get_order_sn(),
  376. 'txn_time' => $current,
  377. 'total_amount' => $money,
  378. ],
  379. 'payerInfo'=>[
  380. 'payer_type'=> 'USER',
  381. 'payer_id'=> $this->prefix.$user_id,
  382. 'payer_accttype'=> 'USEROWN',
  383. 'password'=> $password,
  384. 'random_key'=> $random_key['random_key'],
  385. ]
  386. ];
  387. $url = $url = $this->cloud_url['withdrawal'][$this->env];
  388. $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
  389. $this->success('ok',json_decode($result,true));
  390. }
  391. public function payNotifyTest()
  392. {
  393. $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"}';
  394. $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"}';
  395. $result = json_decode($result,true);
  396. $header = json_decode($header,true);
  397. // var_dump($result,$header);
  398. $check_sign = LLianPayAccpSignature::checkSign(json_encode($result,JSON_UNESCAPED_UNICODE),$header['signature-data']);
  399. var_dump($check_sign);
  400. $orderNo = $result['orderInfo']['txn_seqno'];
  401. var_dump(['out_trade_no' => $orderNo,'user_id'=> trim($result['payerInfo'][0]['payer_id'],$this->prefix)]);
  402. }
  403. }