CloudWallet.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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 = 1; // 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. 'acctserial'=>[
  65. 'https://accpapi-ste.lianlianpay-inc.com/v1/acctmgr/query-acctserial',//测试环境
  66. 'https://accpapi.lianlianpay.com/v1/acctmgr/query-acctserial',//生产环境
  67. ],
  68. ];
  69. public function initialize(){
  70. $this->uid = input('user_id');
  71. parent::initialize();
  72. // parent::check_login();
  73. if(!checkAuth($this->uid))$this->error('暂未开放.....');
  74. }
  75. /**
  76. * @title 申请接入[开户]
  77. * @desc 申请接入[开户]
  78. * @author qc
  79. * @method POST
  80. * @tag 编辑信息
  81. * @url /api/Cloud_wallet/openAcctApply
  82. * @header name:Authorization require:1 desc:Token
  83. * @param name:user_id type:int require:0 default:0 desc:用户id
  84. * @return name:ret_code type:string default:0 desc:0000:成功,其他异常
  85. * @return name:ret_msg type:string default:0 desc:请求结果描述
  86. * @return name:user_status type:string default:0 desc:用户状态【NORMAL:正常,其他异常】
  87. * @return name:bank_open_flag type:int default:0 desc:银行开户标识【0未开户,1已开户,2开户中】
  88. * @return name:bank_account type:string default:0 desc:ACCP合作银行账户
  89. */
  90. public function openAcctApply()
  91. {
  92. $user_id = $this->uid;
  93. $user_info = Db::name('store_member')->find($user_id);
  94. //if(empty($user_info)) $user_info = Db::name('store_member')->find(6);
  95. if(empty($user_info)) $this->error('用户信息有误');
  96. if(!$user_info['true_name'] || !$user_info['id_card']) $this->error('请先实名认证');
  97. //if(!$user_info['bank_num']) $this->error('请绑定银行卡');
  98. $current = date("YmdHis");
  99. $params = [
  100. 'timestamp' => $current,
  101. 'oid_partner' => OID_PARTNER,
  102. 'user_id' => $this->prefix.$user_id,
  103. 'txn_seqno' => get_order_sn(),
  104. 'txn_time' =>$current,
  105. 'flag_chnl' => "H5",
  106. 'notify_url' => 'https://'.$_SERVER['HTTP_HOST'] . '/api/Notify/openAcctApplyNotify',
  107. 'user_type' => 'INNERUSER',
  108. 'basicInfo'=>[
  109. 'reg_phone' => $user_info['phone'] ,
  110. 'user_name' => $user_info['true_name'] ,
  111. 'id_type' => 'ID_CARD',
  112. 'id_no' => $user_info['id_card'] ,
  113. 'occupation' =>18,
  114. ],
  115. 'accountInfo' => [
  116. 'account_type' => 'PERSONAL_PAYMENT_ACCOUNT',
  117. 'account_need_level' => 'V3'
  118. ],
  119. 'linkedAcctInfo'=>[
  120. //'linked_accttype'=> 'LEGALREPT_BANK_CARD',
  121. //'linked_acctno'=> $user_info['bank_num'] ,
  122. ],
  123. ];
  124. //var_dump( json_encode($params,JSON_UNESCAPED_UNICODE));
  125. $url = $this->cloud_url['apply'][$this->env];
  126. $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
  127. $this->success('请求成功',json_decode($result,true));
  128. }
  129. /**
  130. * @title 激活申请
  131. * @desc 激活申请
  132. * @author qc
  133. * @method POST
  134. * @tag 编辑信息
  135. * @url /api/Cloud_wallet/activateApply
  136. * @header name:Authorization require:1 desc:Token
  137. * @param name:user_id type:int require:0 default:0 desc:用户id
  138. * @param name:password type:string require:0 default:0 desc:支付密码。6-12位的字母、数字,不可以是连续或者重复的数字和字母,正则:^[a-zA-Z0-9]{6,12}$。通过密码控件加密成密文传输
  139. * @param name:pkg_name type:string require:0 default:test desc:APP包名[h5或是测试不用传]
  140. * @param name:app_name type:string require:0 default:test desc:APP应用名[h5或是测试不用传]
  141. * @param name:flag_chnl type:string require:0 default:H5 desc:交易发起渠道传H5或APP
  142. * @return name:ret_code type:string default:0 desc:0000:成功,其他异常
  143. * @return name:ret_msg type:string default:0 desc:请求结果描述
  144. * @return name:user_status type:string default:0 desc:用户状态【NORMAL:正常,其他异常】
  145. * @return name:bank_open_flag type:int default:0 desc:银行开户标识【0未开户,1已开户,2开户中】
  146. * @return name:bank_account type:string default:0 desc:ACCP合作银行账户
  147. */
  148. public function activateApply()
  149. {
  150. $user_id = $this->uid;
  151. $password = input('post.password');
  152. $flag_chnl = input('get.flag_chnl','H5');
  153. $pkg_name = input('get.pkg_name');
  154. $app_name = input('get.app_name');
  155. $current = date("YmdHis");
  156. $rand_arr = self::getRandomKey($this->prefix.$user_id, $this->cloud_url['random'][$this->env],$flag_chnl,$pkg_name,$app_name);
  157. if($rand_arr['ret_code'] != '0000') $this->error($rand_arr['ret_msg']);
  158. $params = [
  159. 'timestamp' => $current,
  160. 'oid_partner' => OID_PARTNER,
  161. 'user_id' => $this->prefix.$user_id,
  162. 'txn_seqno' => get_order_sn(),
  163. 'txn_time' =>$current,
  164. 'notify_url' => 'https://'.$_SERVER['HTTP_HOST'] . '/api/Notify/openAcctApplyNotify',
  165. 'password' => $password,
  166. 'random_key' => $rand_arr['random_key'],
  167. 'accountInfo'=>[
  168. 'account_type' => 'PERSONAL_PAYMENT_ACCOUNT'
  169. ]
  170. ];
  171. $url = $this->cloud_url['activate'][$this->env];
  172. $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
  173. $this->success('请求成功',json_decode($result,true));
  174. }
  175. /**
  176. * @title 获取随机因子
  177. * @desc 获取随机因子
  178. * @author qc
  179. * @method GET
  180. * @tag 编辑信息
  181. * @url /api/Cloud_wallet/getRandomKeys
  182. * @header name:Authorization require:1 desc:Token
  183. * @param name:user_id type:int require:0 default:0 desc:用户id
  184. * @param name:pkg_name type:string require:0 default:test desc:APP包名[h5或是测试不用传]
  185. * @param name:app_name type:string require:0 default:test desc:APP应用名[h5或是测试不用传]
  186. * @param name:flag_chnl type:string require:0 default:H5 desc:交易发起渠道传H5或APP
  187. * @return name:ret_code type:string default:0 desc:0000:成功,其他异常
  188. * @return name:ret_msg type:string default:0 desc:请求结果描述
  189. * @return name:random_key type:string default:0 desc:随机因子key,有效期30分钟
  190. * @return name:random_value type:string default:0 desc:随机因子值,有效期30分钟
  191. */
  192. public function getRandomKeys()
  193. {
  194. $user_id = $this->uid;
  195. $flag_chnl = input('get.flag_chnl','H5');
  196. $pkg_name = input('get.pkg_name');
  197. $app_name = input('get.app_name');
  198. $res = self::getRandomKey($this->prefix.$user_id, $this->cloud_url['random'][$this->env],$flag_chnl,$pkg_name,$app_name);
  199. $this->success('请求成功',$res);
  200. }
  201. // 获取随机因子
  202. public static function getRandomKey($user_id,$url,$flag_chnl,$pkg_name,$app_name)
  203. {
  204. $current = date("YmdHis");
  205. $params = [
  206. 'timestamp' => $current,
  207. 'oid_partner' => OID_PARTNER,
  208. 'user_id' => $user_id,
  209. 'flag_chnl' => $flag_chnl,
  210. 'pkg_name' => $flag_chnl == 'H5' ? static::$domain_name :($pkg_name ? $pkg_name : 'test') ,
  211. 'app_name' => $flag_chnl == 'H5' ? static::$domain_name :($app_name ? $app_name : 'test') ,
  212. ];
  213. //var_dump($params);
  214. $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
  215. return json_decode($result,JSON_UNESCAPED_UNICODE);
  216. }
  217. /**
  218. * @title 获取云钱包用户信息
  219. * @desc 获取云钱包用户信息
  220. * @author qc
  221. * @method GET
  222. * @tag 编辑信息
  223. * @url /api/Cloud_wallet/getUserInfo
  224. * @header name:Authorization require:1 desc:Token
  225. * @param name:user_id type:int require:0 default:0 desc:用户id
  226. * @return name:ret_code type:string default:0 desc:0000:成功,其他异常
  227. * @return name:ret_msg type:string default:0 desc:请求结果描述
  228. * @return name:user_status type:string default:0 desc:用户状态【NORMAL:正常,其他异常】
  229. * @return name:bank_open_flag type:int default:0 desc:银行开户标识【0未开户,1已开户,2开户中】
  230. * @return name:bank_account type:string default:0 desc:ACCP合作银行账户
  231. */
  232. public function getUserInfo()
  233. {
  234. $user_id = $this->uid;
  235. $current = date("YmdHis");
  236. $params = [
  237. 'timestamp' => $current,
  238. 'oid_partner' => OID_PARTNER,
  239. 'user_id' => $this->prefix.$user_id,
  240. ];
  241. $url = $url = $this->cloud_url['userinfo'][$this->env];
  242. $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
  243. //$res = LianLianPay::userLevel($this->uid);
  244. // var_dump($res);
  245. $this->success('请求成功',json_decode($result,true));
  246. }
  247. /**
  248. * @title 获取云钱包账户信息
  249. * @desc 获取云钱包账户信息
  250. * @author qc
  251. * @method GET
  252. * @tag 编辑信息
  253. * @url /api/Cloud_wallet/getAcctInfo
  254. * @header name:Authorization require:1 desc:Token
  255. * @param name:user_id type:int require:0 default:0 desc:用户id
  256. * @return name:ret_code type:string default:0 desc:0000:成功,其他异常
  257. * @return name:ret_msg type:string default:0 desc:请求结果描述
  258. * @return name:ret_msg type:string default:0 desc:请求结果描述
  259. * @return name:acctinfo_list type:array default:0 desc:账户列表
  260. * @return name:acctinfo_list.oid_acctno type:string default:0 desc:账户号
  261. * @return name:acctinfo_list.acct_state type:string default:0 desc:账户状态【NORMAL:正常,其他异常】
  262. * @return name:acctinfo_list.amt_balcur type:float default:0 desc:资金余额[单位:元]
  263. * @return name:acctinfo_list.amt_balaval type:float default:0 desc:可用余额[单位:元]
  264. * @return name:acctinfo_list.amt_balfrz type:float default:0 desc:冻结金额[单位:元]
  265. * @return name:acctinfo_list.amt_lastbal type:float default:0 desc:昨日资金余额[单位:元]
  266. * @return name:acctinfo_list.amt_lastaval type:float default:0 desc:昨日可用余额[单位:元]
  267. * @return name:acctinfo_list.amt_lastfrz type:float default:0 desc:昨日冻结金额[单位:元]
  268. * @return name:total_money type:float default:0 desc:总资产
  269. * @return name:total_balaval type:float default:0 desc:总可用
  270. * @return name:total_balfrz type:float default:0 desc:总冻结
  271. *
  272. */
  273. public function getAcctInfo()
  274. {
  275. $user_id = $this->uid;
  276. $current = date("YmdHis");
  277. $params = [
  278. 'timestamp' => $current,
  279. 'oid_partner' => OID_PARTNER,
  280. 'user_id' => $this->prefix.$user_id,
  281. 'user_type' => 'INNERUSER',
  282. ];
  283. $url = $url = $this->cloud_url['acctinfo'][$this->env];
  284. $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
  285. $res = json_decode($result,true);
  286. if(isset($res['acctinfo_list'])) {
  287. $total_money = bcadd($res['acctinfo_list'][0]['amt_balcur'],$res['acctinfo_list'][1]['amt_balcur'],2);
  288. $total_balaval = bcadd($res['acctinfo_list'][0]['amt_balaval'],$res['acctinfo_list'][1]['amt_balaval'],2);
  289. $total_balfrz = bcadd($res['acctinfo_list'][0]['amt_balfrz'],$res['acctinfo_list'][1]['amt_balfrz'],2);
  290. }
  291. $res['total_money'] = !empty($total_money) ? $total_money : 0;
  292. $res['total_balaval'] = !empty($total_balaval) ? $total_balaval : 0;
  293. $res['total_balfrz'] = !empty($total_balfrz) ? $total_balfrz : 0;
  294. $this->success('请求成功',$res);
  295. }
  296. /**
  297. * @title 交易二次短信验证
  298. * @desc 交易二次短信验证
  299. * @author qc
  300. * @method GET
  301. * @tag 编辑信息
  302. * @url /api/Cloud_wallet/validationSms
  303. * @header name:Authorization require:1 desc:Token
  304. * @param name:user_id type:int require:0 default:0 desc:用户id
  305. * @param name:txn_seqno type:int require:0 default:0 desc:订单号
  306. * @param name:total_amount type:int require:0 default:0 desc:订单金额【提现金额】
  307. * @param name:token type:int require:0 default:0 desc:token
  308. * @param name:verify_code type:int require:0 default:0 desc:验证码
  309. * @return name:ret_code type:string default:0 desc:0000:成功,其他异常
  310. * @return name:ret_msg type:string default:0 desc:请求结果描述
  311. */
  312. public function validationSms()
  313. {
  314. $user_id = $this->uid;
  315. $token = input('get.token');
  316. $txn_seqno = input('get.txn_seqno');
  317. $total_amount = input('get.total_amount');
  318. $verify_code = input('get.verify_code');
  319. $current = date("YmdHis");
  320. $params = [
  321. 'timestamp' => $current,
  322. 'oid_partner' => OID_PARTNER,
  323. 'payer_type'=>"USER",
  324. 'payer_id' => $this->prefix.$user_id,
  325. 'txn_seqno'=>$txn_seqno,
  326. 'total_amount'=>$total_amount,
  327. 'token'=>$token,
  328. 'verify_code'=>$verify_code
  329. ];
  330. $url = $this->cloud_url['validation'][$this->env];
  331. $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
  332. $this->success('请求成功',json_decode($result,true));
  333. }
  334. /**
  335. * @title 获取钱包流水
  336. * @desc 获取钱包流水
  337. * @author qc
  338. * @method GET
  339. * @tag 编辑信息
  340. * @url /api/Cloud_wallet/getAcctSerial
  341. * @header name:Authorization require:1 desc:Token
  342. * @param name:user_id type:int require:0 default:0 desc:用户id
  343. * @param name:page type:int require:0 default:1 desc:页数
  344. * @param name:page_num type:int require:0 default:10 desc:每页数量[此处最大是10,默认10]
  345. * @param name:flag_dc type:int require:0 default:-- desc:出入账标识[不传不区分,DEBIT:出账,CREDIT:入账]
  346. * @param name:acct_type type:string require:0 default:USEROWN_PSETTLE desc:账号类型[USEROWN_PSETTLE:用户自有待结算账户,USEROWN_AVAILABLE:用户自有可用账户]
  347. * @return name:ret_code type:string default:0 desc:0000:成功,其他异常
  348. * @return name:ret_msg type:string default:0 desc:请求结果描述
  349. * @return name:page_no type:int default:0 desc:当前页
  350. * @return name:total_page type:int default:0 desc:总页数
  351. * @return name:total_in_amt type:float default:0 desc:入账总金额,表示当前查询条件下的入账总金额,单位:元
  352. * @return name:total_out_amt type:float default:0 desc:出账总金额,表示当前查询条件下的出账总金额,单位:元
  353. * @return name:total_num type:int default:0 desc:总条数
  354. * @return name:acctbal_list type:array default:0 desc:列表
  355. * @return name:acctbal_list.txn_time type:string default:0 desc:商户系统交易时间
  356. * @return name:acctbal_list.amt type:float default:0 desc:出入账金额。单位:元
  357. * @return name:acctbal_list.amt_bal type:float default:0 desc:交易后余额。单位:元
  358. * @return name:acctbal_list.memo type:string default:0 desc:资金流水备注
  359. * @return name:acctbal_list.txn_type type:string default:0 desc:交易类型[用户充值:USER_TOPUP,手续费收取:SERVICE_FEE,普通消费:GENERAL_CONSUME,手续费应收应付核销:CAPITAL_CANCEL]
  360. * @return name:acctbal_list.flag_dc type:string default:0 desc:账户出入账标识[DEBIT:出账,CREDIT:入账]
  361. * @return name:acctbal_list.jno_cli type:string default:0 desc:商户订单号。资金流水对应的商户交易单号,一条商户订单号可能对应多条资金流水
  362. */
  363. public function getAcctSerial()
  364. {
  365. $user_id = $this->uid;
  366. $current = date("YmdHis");
  367. $acct_type = input('acct_type','USEROWN_PSETTLE');
  368. $flag_dc = input('flag_dc','');
  369. $page_no = input('page',1);
  370. $page_size = input('page_num',10);
  371. $params = [
  372. 'timestamp' => $current,
  373. 'oid_partner' => OID_PARTNER,
  374. 'user_id' => $this->prefix.$user_id,
  375. 'user_type' => 'INNERUSER',
  376. 'acct_type' => $acct_type,
  377. 'date_start' => date("YmdHis",strtotime('-180 days')),
  378. 'date_end' => $current,
  379. 'flag_dc' => $flag_dc,
  380. 'page_no' => $page_no,
  381. 'page_size' => $page_size,
  382. ];
  383. // var_dump($params);
  384. $url = $url = $this->cloud_url['acctserial'][$this->env];
  385. $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
  386. $result = json_decode($result,true);
  387. if(!empty($result['acctbal_list']))
  388. {
  389. foreach ($result['acctbal_list'] as &$v) {
  390. $v['date_time'] = date('Y-m-d H:i:s',strtotime($v['txn_time']));
  391. }
  392. }
  393. $this->success('请求成功',$result);
  394. }
  395. /**
  396. * @title 收银台支付测试【测试用不对接】
  397. * @desc 收银台支付测试
  398. * @author qc
  399. * @method GET
  400. * @tag 编辑信息
  401. * @url /api/Cloud_wallet/cashierPay
  402. */
  403. public function cashierPay()
  404. {
  405. $voucher_order = [];
  406. $voucher_order['order_no'] = get_order_sn();
  407. $money = 10;
  408. $from = input('post.from',1);
  409. $user = Db::name('store_member')->where('id',$this->uid)->find();
  410. $notify_url = 'https://'.$_SERVER['HTTP_HOST'] . '/api/Pay/lianLianNotify';
  411. $return_url ='https://'.$_SERVER['HTTP_HOST']."/h5/pages/mine/mine";//回调地址
  412. $risk_item= risk_item($user,'余额充值',$from == 1 ? 16 : 10);
  413. $res= LianLianPay::cashierPay($voucher_order['order_no'],$money,$this->uid,$notify_url,$return_url,'余额充值',[[
  414. 'payee_id'=>OID_PARTNER,
  415. 'payee_type' => 'MERCHANT',
  416. 'payee_amount' => $money,
  417. ]],$risk_item);
  418. $this->success('请求成功',$res);
  419. }
  420. /**
  421. * @title 云钱包提现【测试用不对接】
  422. * @desc 云钱包提现
  423. * @author qc
  424. * @method POST
  425. * @tag 编辑信息
  426. * @url /api/Cloud_wallet/withdrawal
  427. * @header name:Authorization require:1 desc:Token
  428. * @param name:user_id type:int require:0 default:0 desc:用户id
  429. * @param name:source type:int require:0 default:10 desc:app传10,h5传16
  430. * @param name:pkg_name type:string require:0 default:test desc:APP包名[h5或是测试不用传]
  431. * @param name:app_name type:string require:0 default:test desc:APP应用名[h5或是测试不用传]
  432. * @param name:flag_chnl type:string require:0 default:H5 desc:交易发起渠道传H5或ANDROID或IOS
  433. * @return name:ret_code type:string default:0 desc:0000:成功,其他异常
  434. * @return name:ret_msg type:string default:0 desc:请求结果描述
  435. */
  436. public function withdrawal()
  437. {
  438. $user_id = $this->uid;
  439. $money = input('post.money');
  440. $password = input('post.password');
  441. $flag_chnl = input('get.flag_chnl','H5');
  442. $pkg_name = input('get.pkg_name');
  443. $app_name = input('get.app_name');
  444. $random_key = self::getRandomKey($this->prefix.$user_id, $this->cloud_url['random'][$this->env],$flag_chnl,$pkg_name,$app_name);
  445. $current = date("YmdHis");
  446. $user_info = Db::name('store_member')->where('id',$user_id)->find();
  447. $risk_item = risk_item($user_info,'余额提现',input('post,source',10));
  448. $notify_url = 'https://'.$_SERVER['HTTP_HOST'] . '/api/Pay/withdrawalNotify';
  449. $params = [
  450. 'timestamp' => $current,
  451. 'oid_partner' => OID_PARTNER,
  452. 'notify_url'=> $notify_url,
  453. 'risk_item'=>json_encode($risk_item),
  454. 'linked_acctno'=>$user_info['bank_num'],
  455. 'check_flag'=> 'N',
  456. 'pay_time_type'=> 'TRANS_NORMAL',
  457. 'orderInfo'=>[
  458. 'txn_seqno'=>get_order_sn(),
  459. 'txn_time' => $current,
  460. 'total_amount' => $money,
  461. ],
  462. 'payerInfo'=>[
  463. 'payer_type'=> 'USER',
  464. 'payer_id'=> $this->prefix.$user_id,
  465. 'payer_accttype'=> 'USEROWN',
  466. 'password'=> $password,
  467. 'random_key'=> $random_key['random_key'],
  468. ]
  469. ];
  470. $url = $url = $this->cloud_url['withdrawal'][$this->env];
  471. $result = LLianPayClient::sendRequest($url, json_encode($params,JSON_UNESCAPED_UNICODE));
  472. $this->success('请求成功',json_decode($result,true));
  473. }
  474. public function payNotifyTest()
  475. {
  476. $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"}';
  477. $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"}';
  478. $result = json_decode($result,true);
  479. $header = json_decode($header,true);
  480. // var_dump($result,$header);
  481. $check_sign = LLianPayAccpSignature::checkSign(json_encode($result,JSON_UNESCAPED_UNICODE),$header['signature-data']);
  482. var_dump($check_sign);
  483. $orderNo = $result['orderInfo']['txn_seqno'];
  484. var_dump(['out_trade_no' => $orderNo,'user_id'=> trim($result['payerInfo'][0]['payer_id'],$this->prefix)]);
  485. }
  486. }