HuifuService.php 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613
  1. <?php
  2. namespace addons\HuifuPay\common\service;
  3. use addons\HuifuPay\common\models\HuifupayPayRequestLog;
  4. use addons\HuifuPay\common\service\params\HuifuBalancePayParam;
  5. use addons\HuifuPay\common\service\params\HuifuBalancePayRefundParam;
  6. use addons\HuifuPay\common\service\params\HuifuFastPayParam;
  7. use addons\HuifuPay\common\service\params\HuifuBalanceOnlineRefundParam;
  8. use addons\HuifuPay\common\service\params\HuifuMerchantBusiModifyParam;
  9. use BsPaySdk\core\BsPay;
  10. use BsPaySdk\core\BsPayClient;
  11. use BsPaySdk\core\BsPayTools;
  12. use BsPaySdk\request\BaseRequest;
  13. use BsPaySdk\request\V2MerchantBusiOpenRequest;
  14. use BsPaySdk\request\V2QuickbuckleApplyRequest;
  15. use BsPaySdk\request\V2QuickbuckleUnbindRequest;
  16. use BsPaySdk\request\V2TradeAcctpaymentPayRequest;
  17. use BsPaySdk\request\V2TradeAcctpaymentRefundRequest;
  18. use BsPaySdk\request\V2TradeHostingPaymentPreorderAliRequest;
  19. use BsPaySdk\request\V2TradeHostingPaymentPreorderWxRequest;
  20. use BsPaySdk\request\V2TradeOnlinepaymentTransferAccountRequest;
  21. use BsPaySdk\request\V2TradePaymentDelaytransConfirmRequest;
  22. use BsPaySdk\request\V2TradePaymentJspayRequest;
  23. use BsPaySdk\request\V2TradePaymentScanpayRefundRequest;
  24. use BsPaySdk\request\V2TradeOnlinepaymentQuickpayApplyRequest;
  25. use BsPaySdk\request\V2QuickbuckleConfirmRequest;
  26. use BsPaySdk\request\V2TradeOnlinepaymentQuickpayConfirmRequest;
  27. use BsPaySdk\request\V2TradeOnlinepaymentRefundRequest;
  28. use BsPaySdk\request\V2MerchantBusiModifyRequest;
  29. use common\enums\AddonsEnum;
  30. # 以下配置为开发联调时覆盖SDK的配置项,需在引入SDK的init.php之前配置以覆盖SDK初始配置
  31. # 设置是否调试模式,不配置默认关闭:false
  32. define("DEBUG", true);
  33. # 设置调试日志路径,不配置默认为SDK同级的log目录下
  34. //define("LOG", dirname(__FILE__) . "/log");
  35. define("LOG", \Yii::$app->basePath . '/../api/runtime/huifu');
  36. # 设置生产模式,不配置默认生产模式:true
  37. //define("PROD_MODE", false);
  38. # SDK 初始化文件加载
  39. require_once dirname(__FILE__) . "/../BsPaySdk/init.php";
  40. require_once dirname(__FILE__) . "/../BsPaySdk/request/V2QuickbuckleApplyRequest.php";
  41. require_once dirname(__FILE__) . "/../BsPaySdk/request/V2QuickbuckleUnbindRequest.php";
  42. require_once dirname(__FILE__) . "/../BsPaySdk/request/V2TradePaymentJspayRequest.php";
  43. require_once dirname(__FILE__) . "/../BsPaySdk/request/V2TradeHostingPaymentPreorderWxRequest.php";
  44. require_once dirname(__FILE__) . "/../BsPaySdk/request/V2TradePaymentScanpayRefundRequest.php";
  45. require_once dirname(__FILE__) . "/../BsPaySdk/request/V2TradeOnlinepaymentTransferAccountRequest.php";
  46. require_once dirname(__FILE__) . "/../BsPaySdk/request/V2TradeHostingPaymentPreorderAliRequest.php";
  47. require_once dirname(__FILE__) . "/../BsPaySdk/request/V2TradeAcctpaymentPayRequest.php";
  48. require_once dirname(__FILE__) . "/../BsPaySdk/request/V2TradeAcctpaymentRefundRequest.php";
  49. require_once dirname(__FILE__) . "/../BsPaySdk/request/V2QuickbuckleConfirmRequest.php";
  50. require_once dirname(__FILE__) . "/../BsPaySdk/request/V2TradeOnlinepaymentQuickpayApplyRequest.php";
  51. require_once dirname(__FILE__) . "/../BsPaySdk/request/V2TradeOnlinepaymentQuickpayConfirmRequest.php";
  52. require_once dirname(__FILE__). "/../BsPaySdk/request/V2TradeOnlinepaymentRefundRequest.php";
  53. require_once dirname(__FILE__). "/../BsPaySdk/request/V2TradePaymentDelaytransConfirmRequest.php";
  54. require_once dirname(__FILE__). "/../BsPaySdk/request/V2MerchantBusiModifyRequest.php";
  55. require_once dirname(__FILE__). "/../BsPaySdk/request/V2MerchantBusiOpenRequest.php";
  56. use common\traits\ErrorTrait;
  57. use ReflectionClass;
  58. use RuntimeException;
  59. use yii\db\Exception;
  60. use \Yii;
  61. class HuifuService
  62. {
  63. use ErrorTrait;
  64. public $public_key = '';
  65. public $config = [];
  66. public $mall_id;
  67. public $requestId;
  68. public function __construct($mall_id = null)
  69. {
  70. if (!empty($mall_id)) {
  71. $this->config = \Yii::$app->services->setting->addons->get($mall_id, AddonsEnum::ADDONS_NAME_HUIFU_PAY, 'basic');
  72. # init方法,从 config.json 加载系统参数
  73. $config = [
  74. 'sys_id' => $this->config['huifupay_sys_id'],
  75. 'product_id' => $this->config['huifupay_product_id'],
  76. 'rsa_merch_private_key' => $this->config['huifupay_private_key'],
  77. 'rsa_huifu_public_key' => $this->config['huifupay_public_key'],
  78. ];
  79. $this->public_key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($this->config['huifupay_public_key'], 64, "\n", true) . "\n-----END PUBLIC KEY-----";
  80. BsPay::init($config, true);
  81. $this->mall_id = $mall_id;
  82. }
  83. }
  84. public function verifySign($signature, $data)
  85. {
  86. return BsPayTools::verifySign_sort($signature, $data, $this->config['huifupay_public_key']);
  87. }
  88. /**
  89. * 作者:zengfanhua
  90. * 创建时间:2024/05/29 12:59:02
  91. * 大额转账要素切换
  92. * 01-四要素(卡号,户名,金额,调账标识),05-三要素(金额+姓名+12位纯数字打款标识);示例值:01
  93. */
  94. //
  95. public function merchantBusiBigPayModify($type='05')
  96. {
  97. // 2.组装请求参数
  98. $request = new V2MerchantBusiModifyRequest();
  99. // 请求流水号
  100. $request->setReqSeqId(date("YmdHis") . mt_rand());
  101. // 请求日期
  102. $request->setReqDate(date("Ymd"));
  103. // 汇付客户Id
  104. $request->setHuifuId($this->config['huifupay_huifu_id']);
  105. // 设置非必填字段
  106. $param['biz_type']=$type;
  107. $extendInfoMap = HuifuMerchantBusiModifyParam::getExtendInfosNoInfo($param);
  108. $request->setExtendInfo($extendInfoMap);
  109. // 3. 发起API调用
  110. $result = $this->postRequest($request);
  111. if (!$result || $result->isError()) { //失败处理
  112. throw new Exception($result->getErrorInfo());
  113. } else { //成功处理
  114. $resData = $result->getRspDatas();
  115. $resData = $resData['data'];
  116. if ($resData['resp_code'] == '00000000' || $resData['resp_code'] == '00000100') {
  117. return $resData;
  118. }
  119. throw new Exception($resData['resp_desc']);
  120. }
  121. }
  122. /**
  123. * 作者:zengfanhua
  124. * 创建时间:2024/01/08 12:59:02
  125. * 余额支付(这是一个同步响应操作)
  126. */
  127. public function balancePay($data, $splitAccount = [])
  128. {
  129. // 2.组装请求参数
  130. $request = new V2TradeAcctpaymentPayRequest();
  131. // 请求流水号
  132. $request->setReqSeqId(date("YmdHis") . mt_rand());
  133. // 请求日期
  134. $request->setReqDate(date("Ymd"));
  135. // 出款方商户号
  136. $request->setOutHuifuId($data['huifu_id']);
  137. // 支付金额
  138. $request->setOrdAmt($data['amount']);
  139. // 分账对象
  140. $request->setAcctSplitBunch(HuifuBalancePayParam::getAcctSplitBunch($splitAccount));
  141. // 安全信息
  142. $request->setRiskCheckData(HuifuBalancePayParam::getRiskCheckData());
  143. // 设置非必填字段
  144. $extendInfoMap = HuifuBalancePayParam::getExtendInfos();
  145. $request->setExtendInfo($extendInfoMap);
  146. // 3. 发起API调用
  147. $result = $this->postRequest($request);
  148. if (!$result || $result->isError()) { //失败处理
  149. throw new Exception($result->getErrorInfo());
  150. } else { //成功处理
  151. $resData = $result->getRspDatas();
  152. $resData = $resData['data'];
  153. if ($resData['resp_code'] == '00000000' || $resData['resp_code'] == '00000100') {
  154. return $resData;
  155. }
  156. throw new Exception($resData['resp_desc']);
  157. }
  158. }
  159. /**
  160. * 作者:zengfanhua
  161. * 创建时间:2024/01/08 12:59:02
  162. * 余额支付退款
  163. */
  164. public function balanceReturn($data, $splitAccount)
  165. {
  166. // 2.组装请求参数
  167. $request = new V2TradeAcctpaymentRefundRequest();
  168. // 请求流水号
  169. $request->setReqSeqId(date("YmdHis") . mt_rand());
  170. // 请求日期
  171. $request->setReqDate(date("Ymd"));
  172. // 商户号
  173. $request->setHuifuId($data['huifu_id']);
  174. // 原余额支付请求日期org_hf_seq_id和(orgReqDate+orgReqSeqId)二选一;&lt;br/&gt;格式:yyyyMMdd;&lt;font color&#x3D;&quot;green&quot;&gt;示例值:20221023&lt;/font&gt;
  175. $request->setOrgReqDate($data['old_req_date']);
  176. // 原余额支付请求流水号org_hf_seq_id和(orgReqDate+orgReqSeqId)二选一;&lt;br/&gt;&lt;font color&#x3D;&quot;green&quot;&gt;示例值:2021091708126665001&lt;/font&gt;
  177. $request->setOrgReqSeqId($data['org_req_seq_id']);
  178. // 原余额支付支付全局流水号org_hf_seq_id和(orgReqDate+orgReqSeqId)二选一;&lt;br/&gt;&lt;font color&#x3D;&quot;green&quot;&gt;示例值:00470topo1A211015160805P090ac132fef00000&lt;/font&gt;
  179. $request->setOrgHfSeqId("");
  180. // 退款金额
  181. $request->setOrdAmt($data['amount']);
  182. // 设置非必填字段
  183. $extendInfoMap = HuifuBalancePayRefundParam::getExtendInfos($splitAccount);
  184. if (!empty($data['delay_acct_flag'])) $extendInfoMap['delay_acct_flag'] = $data['delay_acct_flag'];
  185. $request->setExtendInfo($extendInfoMap);
  186. // 3. 发起API调用
  187. $result = $this->postRequest($request);
  188. if (!$result || $result->isError()) { //失败处理
  189. throw new Exception($result->getErrorInfo());
  190. } else { //成功处理
  191. $resData = $result->getRspDatas();
  192. $resData = $resData['data'];
  193. if ($resData['resp_code'] == '00000000' || $resData['resp_code'] == '00000100') {
  194. return $resData;
  195. }
  196. throw new Exception($resData['resp_desc']);
  197. }
  198. }
  199. /**
  200. * 大额支付
  201. */
  202. public function bigPay($notify_url, $data)
  203. {
  204. // 2.组装请求参数
  205. $request = new V2TradeOnlinepaymentTransferAccountRequest();
  206. // 请求流水号
  207. $request->setReqSeqId(date("YmdHis") . mt_rand());
  208. // 请求日期
  209. $request->setReqDate(date("Ymd"));
  210. // 收款方商户号
  211. $request->setHuifuId($data['huifu_id']);
  212. // 交易金额
  213. $request->setTransAmt($data['amount']);
  214. // 商品描述
  215. $request->setGoodsDesc($data['goods_title']);
  216. //基本信息
  217. $extendInfoMap = array();
  218. // // 收款方用户客户号
  219. //$extendInfoMap["user_huifu_id"] = $data['huifu_id'];
  220. // // 收款方账户号
  221. // $extendInfoMap["acct_id"] = "";
  222. // 付款方名称
  223. $extendInfoMap["certificate_name"] = $data['real_name'];
  224. // 付款方银行卡号
  225. $extendInfoMap["bank_card_no"] = BsPayTools::encrypt_with_rsa_pubkey($data['bank_card_no'], $this->config['huifupay_public_key']);
  226. // 订单类型
  227. // $extendInfoMap["order_type"]= "";
  228. // 备注
  229. $extendInfoMap["remark"] = "";
  230. // 异步通知地址
  231. $extendInfoMap["notify_url"] = $notify_url;
  232. if (!empty($data['delay_acct_flag'])) $extendInfoMap['delay_acct_flag'] = $data['delay_acct_flag'];
  233. // 设置非必填字段
  234. $request->setExtendInfo($extendInfoMap);
  235. // 3. 发起API调用
  236. $result = $this->postRequest($request);
  237. if (!$result || $result->isError()) { //失败处理
  238. throw new Exception($result->getErrorInfo());
  239. } else { //成功处理
  240. $resData = $result->getRspDatas();
  241. $resData = $resData['data'];
  242. if ($resData['resp_code'] == '00000000' || $resData['resp_code'] == '00000100') {
  243. return $resData;
  244. }
  245. throw new Exception($resData['resp_desc']);
  246. }
  247. }
  248. /**
  249. * 作者:zengfanhua
  250. * 创建时间:2024/01/03 15:44:57
  251. * 线上交易退款
  252. */
  253. public function onlineRefund($data, $splitAccount = [])
  254. {
  255. // 2.组装请求参数
  256. $request = new V2TradeOnlinepaymentRefundRequest();
  257. // 请求日期
  258. $request->setReqDate(date("Ymd"));
  259. // 请求流水号
  260. $request->setReqSeqId(date("YmdHis") . mt_rand());
  261. // 商户号
  262. $request->setHuifuId($data['huifu_id']);
  263. // 退款金额
  264. $request->setOrdAmt($data['amount']);
  265. // 设备信息
  266. $request->setTerminalDeviceData(HuifuBalanceOnlineRefundParam::getTerminalDeviceData());
  267. // 安全信息
  268. $request->setRiskCheckData(HuifuBalanceOnlineRefundParam::getRiskCheckData());
  269. // 设置非必填字段
  270. $extendInfoMap = HuifuBalanceOnlineRefundParam::getExtendInfos($data,$splitAccount);
  271. $request->setExtendInfo($extendInfoMap);
  272. // 3. 发起API调用
  273. $result = $this->postRequest($request);
  274. if (!$result || $result->isError()) { //失败处理
  275. throw new Exception($result->getErrorInfo());
  276. } else { //成功处理
  277. $resData = $result->getRspDatas();
  278. $resData = $resData['data'];
  279. if ($resData['resp_code'] == '00000000' || $resData['resp_code'] == '00000100') {
  280. return $resData;
  281. }
  282. throw new Exception($resData['resp_desc']);
  283. }
  284. }
  285. /**
  286. * 作者:zengfanhua
  287. * 创建时间:2024/01/03 15:44:57
  288. * 扫码交易退款
  289. */
  290. public function refund($data, $splitAccount = [])
  291. {
  292. // 2.组装请求参数
  293. $request = new V2TradePaymentScanpayRefundRequest();
  294. // 请求日期
  295. $request->setReqDate(date("Ymd"));
  296. // 请求流水号
  297. $request->setReqSeqId(date("YmdHis") . mt_rand());
  298. // 商户号
  299. $request->setHuifuId($data['huifu_id']);
  300. // 申请退款金额
  301. $request->setOrdAmt($data['amount']);
  302. // 原交易请求日期
  303. $request->setOrgReqDate($data['old_req_date']);
  304. // 设置非必填字段
  305. $extendInfoMap = HuifuRefundParam::getExtendInfos($data['org_req_seq_id'], $splitAccount);
  306. $request->setExtendInfo($extendInfoMap);
  307. // 3. 发起API调用
  308. $result = $this->postRequest($request);
  309. if (!$result || $result->isError()) { //失败处理
  310. throw new Exception($result->getErrorInfo());
  311. } else { //成功处理
  312. $resData = $result->getRspDatas();
  313. $resData = $resData['data'];
  314. if ($resData['resp_code'] == '00000000' || $resData['resp_code'] == '00000100') {
  315. return $resData;
  316. }
  317. throw new Exception($resData['resp_desc']);
  318. }
  319. }
  320. /**
  321. * 作者:zengfanhua-支付托管
  322. * 创建时间:2023/12/30 10:27:21
  323. * 微信小程序预下单接口
  324. * @data 数据
  325. * @notify_url 通知地址
  326. * @expireDate 过期时间
  327. * @return array
  328. */
  329. public function preWxOrder($data, $notify_url, $expireDate, $splitAccount = [])
  330. {
  331. // 2.组装请求参数
  332. $request = new V2TradeHostingPaymentPreorderWxRequest();
  333. // 预下单类型
  334. $request->setPreOrderType("3");
  335. // 请求日期
  336. $request->setReqDate(date("Ymd"));
  337. // 请求流水号
  338. $request->setReqSeqId(date("YmdHis") . mt_rand());
  339. // 商户号
  340. $request->setHuifuId($data['huifu_id']);
  341. // 交易金额
  342. $request->setTransAmt($data['amount']);
  343. // 商品描述
  344. $request->setGoodsDesc($data['goods_title']);
  345. // 微信小程序扩展参数集合
  346. $request->setMiniappData(HuifuPreOrderParam::getMiniappDataRucan());
  347. // 设置非必填字段
  348. $extendInfoMap = HuifuPreOrderParam::getExtendInfos($expireDate, $notify_url, $splitAccount);
  349. if (!empty($data['delay_acct_flag'])) $extendInfoMap['delay_acct_flag'] = $data['delay_acct_flag'];
  350. $request->setExtendInfo($extendInfoMap);
  351. // 3. 发起API调用
  352. $result = $this->postRequest($request);
  353. if (!$result || $result->isError()) { //失败处理
  354. throw new Exception(is_string($result->getErrorInfo()) ? $result->getErrorInfo() : var_export($result->getErrorInfo(), true));
  355. } else { //成功处理
  356. $resData = $result->getRspDatas();
  357. $resData = $resData['data'];
  358. if ($resData['resp_code'] == '00000000' || $resData['resp_code'] == '00000100') {
  359. return $resData;
  360. }
  361. throw new Exception($resData['resp_desc']);
  362. }
  363. }
  364. /**
  365. * 支付产品
  366. * @param $data
  367. * @param $notify_url
  368. * @param $expireDate
  369. * @param $splitAccount
  370. * @return mixed
  371. * @throws Exception
  372. */
  373. public function preWxOrder2($data, $notify_url, $expireDate, $splitAccount = [])
  374. {
  375. try {
  376. // 2.组装请求参数
  377. $request = new V2TradePaymentJspayRequest();
  378. // 请求流水号
  379. $request->setReqSeqId(date("YmdHis") . mt_rand());
  380. // 请求日期
  381. $request->setReqDate(date("Ymd"));
  382. // 汇付ID
  383. $request->setHuifuId($data['huifu_id']);
  384. // 交易金额
  385. $request->setTransAmt($data['amount']);
  386. // 商品描述
  387. $request->setGoodsDesc($data['goods_title']);
  388. $request->setTradeType($data['trade_type']);
  389. // 微信参数集合
  390. $request->setWxData(HuifuJsPayParam::getWxData($data['mall_id'],$data['open_id']));
  391. // 设置非必填字段
  392. $extendInfoMap = HuifuPreOrderParam::getExtendInfos($expireDate, $notify_url, $splitAccount);
  393. if (!empty($data['delay_acct_flag'])) $extendInfoMap['delay_acct_flag'] = $data['delay_acct_flag'];
  394. $request->setExtendInfo($extendInfoMap);
  395. // 3. 发起API调用
  396. $result = $this->postRequest($request);
  397. if (!$result || $result->isError()) { //失败处理
  398. throw new Exception(is_string($result->getErrorInfo()) ? $result->getErrorInfo() : var_export($result->getErrorInfo(), true));
  399. } else { //成功处理
  400. $resData = $result->getRspDatas();
  401. $resData = $resData['data'];
  402. if ($resData['resp_code'] == '00000000' || $resData['resp_code'] == '00000100') {
  403. return $resData;
  404. }
  405. throw new Exception($resData['resp_code'].$resData['resp_desc']);
  406. }
  407. }catch (\Exception $e){
  408. throw new Exception($e->getMessage());
  409. }
  410. }
  411. /**
  412. * 作者:zengfanhua
  413. * 创建时间:2023/12/30 10:27:21
  414. * 支付宝预下单接口
  415. * @data 数据
  416. * @notify_url 通知地址
  417. * @expireDate 过期时间
  418. * @return array
  419. */
  420. public function preAliOrder($data, $notify_url, $expireDate, $splitAccount = [])
  421. {
  422. // 2.组装请求参数
  423. $request = new V2TradeHostingPaymentPreorderAliRequest();
  424. // 预下单类型
  425. $request->setPreOrderType("2");
  426. // 请求日期
  427. $request->setReqDate(date("Ymd"));
  428. // 请求流水号
  429. $request->setReqSeqId(date("YmdHis") . mt_rand());
  430. // 商户号
  431. $request->setHuifuId($data['huifu_id']);
  432. // 交易金额
  433. $request->setTransAmt($data['amount']);
  434. // 商品描述
  435. $request->setGoodsDesc($data['goods_title']);
  436. // app扩展参数集合
  437. $dto = array();
  438. // 小程序返回码
  439. $dto["app_schema"] = "app跳转链接";
  440. // 私有信息
  441. // $dto["private_info"] = "";
  442. $request->setAppData(json_encode($dto, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
  443. // 设置非必填字段
  444. $extendInfoMap = HuifuPreOrderParam::getExtendInfos($expireDate, $notify_url, $splitAccount);
  445. if (!empty($data['delay_acct_flag'])) $extendInfoMap['delay_acct_flag'] = $data['delay_acct_flag'];
  446. $request->setExtendInfo($extendInfoMap);
  447. // 3. 发起API调用
  448. $result = $this->postRequest($request);
  449. if (!$result || $result->isError()) { //失败处理
  450. throw new Exception(is_string($result->getErrorInfo()) ? $result->getErrorInfo() : var_export($result->getErrorInfo(), true));
  451. } else { //成功处理
  452. $resData = $result->getRspDatas();
  453. $resData = $resData['data'];
  454. if ($resData['resp_code'] == '00000000' || $resData['resp_code'] == '00000100') {
  455. return $resData;
  456. }
  457. throw new Exception($resData['resp_desc']);
  458. }
  459. }
  460. /**
  461. * 作者:zengfanhua
  462. * 创建时间:2023/12/28 13:02:41
  463. * 聚合正扫接口
  464. * @data 数据
  465. * @notify_url 通知地址
  466. * @expireDate 过期时间
  467. * @wxData 微信扩展信息
  468. * @alipayData 支付宝扩展信息
  469. */
  470. public function jsPay($data, $notify_url, $expireDate, $splitAccount = [], $wxData = [], $alipayData = [])
  471. {
  472. // 2.组装请求参数
  473. $request = new V2TradePaymentJspayRequest();
  474. // 请求日期
  475. $request->setReqDate(date("Ymd"));
  476. // 请求流水号
  477. $request->setReqSeqId(date("YmdHis") . mt_rand());
  478. // 商户号
  479. $request->setHuifuId($this->config['huifu_id']);
  480. // 商品描述
  481. $request->setGoodsDesc($data['goods_title']);
  482. // 交易类型
  483. $request->setTradeType($data['trade_type']);
  484. // 交易金额
  485. $request->setTransAmt($data['amount']);
  486. // 设置非必填字段
  487. $extendInfoMap = HuifuJsPayParam::getExtendInfos($notify_url, $wxData, $alipayData, $expireDate, $splitAccount = []);
  488. if (!empty($data['delay_acct_flag'])) $extendInfoMap['delay_acct_flag'] = $data['delay_acct_flag'];
  489. $request->setExtendInfo($extendInfoMap);
  490. // 3. 发起API调用
  491. $result = $this->postRequest($request);
  492. if (!$result || $result->isError()) { //失败处理
  493. throw new Exception($result->getErrorInfo());
  494. } else { //成功处理
  495. $resData = $result->getRspDatas();
  496. $resData = $resData['data'];
  497. if ($resData['resp_code'] == '00000000' || $resData['resp_code'] == '00000100') {
  498. return $resData;
  499. }
  500. throw new Exception($resData['resp_desc']);
  501. }
  502. }
  503. /**
  504. * 作者:zengfanhua
  505. * 创建时间:2023/12/28 13:05:32
  506. * 签约银行卡
  507. * @param array data UserBankCard->id
  508. * @throws Exception
  509. * @return bool
  510. */
  511. public function signCard($data)
  512. {
  513. // 2.组装请求参数
  514. $request = new V2QuickbuckleApplyRequest;
  515. // 请求日期
  516. $request->setReqDate(date("Ymd"));
  517. // 请求流水号
  518. $request->setReqSeqId(date("YmdHis") . mt_rand());
  519. // 汇付客户Id
  520. $request->setHuifuId($data['huifu_id']);
  521. // 商户用户id
  522. $request->setOutCustId($data['user_id']);
  523. // 订单号
  524. $request->setOrderId($data['order_no']);
  525. // 订单日期
  526. $request->setOrderDate(date("Ymd"));
  527. // 银行卡号
  528. $card_id_rsa = BsPayTools::encrypt_with_rsa_pubkey($data['bank_card_no'], $this->config['huifupay_public_key']);
  529. $request->setCardId($card_id_rsa);
  530. // 银行卡开户姓名
  531. $real_name_rsa = BsPayTools::encrypt_with_rsa_pubkey($data['payer_name'], $this->config['huifupay_public_key']);
  532. $request->setCardName($real_name_rsa);
  533. // 银行卡绑定证件类型
  534. $request->setCertType("00");
  535. // 银行卡绑定身份证
  536. $user_id_rsa = BsPayTools::encrypt_with_rsa_pubkey($data['id_no'], $this->config['huifupay_public_key']);
  537. $request->setCertId($user_id_rsa);
  538. // 个人证件有效期类型
  539. $request->setCertValidityType($data['is_longer'] ? "1" : '0');
  540. // 个人证件有效期起始日
  541. $request->setCertBeginDate(str_replace('-', '', $data['sdate']));
  542. // 个人证件有效期到期日长期有效不填;&lt;font color&#x3D;&quot;green&quot;&gt;示例值:20420905&lt;/font&gt;
  543. $request->setCertEndDate($data['is_longer'] ? '' : str_replace('-', '', $data['edate']));
  544. // 银行卡绑定手机号
  545. $mobile_rsa = BsPayTools::encrypt_with_rsa_pubkey($data['mobile_no'], $this->config['huifupay_public_key']);
  546. $request->setCardMp($mobile_rsa);
  547. // CVV2信用卡交易专用需要密文传输。&lt;br/&gt;使用汇付RSA公钥加密(加密前3位,加密后最长2048位),[参见参考文档](https://paas.huifu.com/partners/guide/#/api_jiami_jiemi);&lt;br/&gt;&lt;font color&#x3D;&quot;green&quot;&gt;示例值:Ly+fnExeyPOTzfOtgRRur77nJB9TAe4PGgK9M……fc6XJXZss&#x3D;&lt;/font&gt;
  548. $request->setVipCode('');
  549. // 卡有效期信用卡交易专用,格式:MMYY,需要密文传输;&lt;br/&gt;使用汇付RSA公钥加密(加密前4位,加密后最长2048位),[参见参考文档](https://paas.huifu.com/partners/guide/#/api_jiami_jiemi);&lt;br/&gt;&lt;font color&#x3D;&quot;green&quot;&gt;示例值:Ly+fnExeyPOTzfOtgRRur77nJB9TAe4PGgK9M……fc6XJXZss&#x3D;JXZss&#x3D;&lt;/font&gt;
  550. // $request->setExpiration("test");
  551. // 挂网协议编号授权信息(招行绑卡需要上送);&lt;font color&#x3D;&quot;green&quot;&gt;示例值:34463343&lt;/font&gt;
  552. // $request->setProtocolNo("test");
  553. // 设备信息域
  554. // $request->setTrxDeviceInf(getTrxDeviceInf());
  555. // 设置非必填字段
  556. $extendInfoMap = HuifuSignParam::getExtendInfos();
  557. $request->setExtendInfo($extendInfoMap);
  558. // 3. 发起API调用
  559. $result = $this->postRequest($request);
  560. if (!$result || $result->isError()) { //失败处理
  561. throw new Exception($result->getErrorInfo());
  562. } else { //成功处理
  563. $resData = $result->getRspDatas();
  564. $resData = $resData['data'];
  565. if ($resData['resp_code'] == '00000000' || $resData['resp_code'] == '00000100') {
  566. return $resData;
  567. }
  568. throw new Exception($resData['resp_desc']);
  569. }
  570. }
  571. /**
  572. * 解绑银行卡
  573. * @param $data
  574. * @return true
  575. */
  576. public function unbindBankCard($data)
  577. {
  578. try {
  579. $request = new V2QuickbuckleUnbindRequest;
  580. // 请求日期
  581. $request->setReqDate(date("Ymd"));
  582. // 请求流水号
  583. $request->setReqSeqId(date("YmdHis") . mt_rand());
  584. // 请求商户Id
  585. $request->setHuifuId($data['huifu_id']);
  586. // 商户用户id
  587. $request->setOutCustId($data['user_id']);
  588. // 银行卡号卡密
  589. $request->setTokenNo($data['sign_no']);
  590. $client = new BsPayClient();
  591. $result = $client->postRequest($request);
  592. if (!$result || $result->isError()) { //失败处理
  593. throw new Exception($result->getErrorInfo());
  594. } else { //成功处理
  595. $resData = $result->getRspDatas();
  596. $resData = $resData['data'];
  597. if ($resData['resp_code'] == '00000000' || $resData['trans_status'] == 'S') {
  598. return true;
  599. }
  600. throw new Exception($resData['resp_desc']);
  601. }
  602. } catch (\Exception $e) {
  603. Yii::$app->custom->logs('请求错误', $e->getMessage());
  604. throw new \Exception($e->getMessage());
  605. }
  606. }
  607. /**
  608. * 作者:zengfanhua
  609. * 创建时间:2023/12/28 13:05:32
  610. * 确认绑定
  611. * @param array data UserBankCard->id
  612. * @throws Exception
  613. * @return bool
  614. */
  615. public function confirmBindSms($data)
  616. {
  617. // 2.组装请求参数
  618. $request = new V2QuickbuckleConfirmRequest();
  619. // 请求日期
  620. $request->setReqDate(date("Ymd"));
  621. // 请求流水号
  622. $request->setReqSeqId(date("YmdHis") . mt_rand());
  623. // 汇付商户Id
  624. $request->setHuifuId($data['huifu_id']);
  625. // 用户id
  626. $request->setOutCustId($data['user_id']);
  627. // 订单号
  628. $request->setOrderId($data['order_no']);
  629. // 订单日期
  630. $request->setOrderDate(date("Ymd"));
  631. // 银行卡号
  632. $card_id_rsa = BsPayTools::encrypt_with_rsa_pubkey($data['bank_card_no'], $this->config['huifupay_public_key']);
  633. $request->setCardId($card_id_rsa);
  634. // 银行卡开户姓名
  635. $real_name_rsa = BsPayTools::encrypt_with_rsa_pubkey($data['payer_name'], $this->config['huifupay_public_key']);
  636. $request->setCardName($real_name_rsa);
  637. // 银行卡绑定证件类型
  638. $request->setCertType("00");
  639. // 银行卡绑定身份证
  640. $user_id_rsa = BsPayTools::encrypt_with_rsa_pubkey($data['id_no'], $this->config['huifupay_public_key']);
  641. $request->setCertId($user_id_rsa);
  642. // 银行卡绑定手机号
  643. $mobile_rsa = BsPayTools::encrypt_with_rsa_pubkey($data['mobile_no'], $this->config['huifupay_public_key']);
  644. $request->setCardMp($mobile_rsa);
  645. // 验证码
  646. $request->setVerifyCode($data['code']);
  647. // CVV2信用卡代扣专用需要密文传输,使用汇付RSA公钥加密(加密前3位,加密后最长2048位),[参见参考文档](https://paas.huifu.com/partners/guide/#/api_jiami_jiemi);&lt;br/&gt;&lt;font color&#x3D;&quot;green&quot;&gt;示例值:Ly+fnExeyPOTzf……rGq0l0NTebfc6XJXZss&#x3D;&lt;/font&gt;
  648. //$request->setVipCode("BndOZvPCXIMcRJi1uCkw4DiNHht+KkARa+sbKbiLh4cXhjywxYM8GMl7g1a5cc1aD2PD6rVvnGzhhgpJ8mzeb/gbzNcYbU5hEXJZm5HShghGucQJB/SoqCIlyaWlz3hnclaGzznWJa5qNa50mCxVqX4zbpuGPWXv+8AnYTu8/Vk=");
  649. // 卡有效期信用卡代扣专用,格式:MMYY,需要密文传输。&lt;br/&gt;使用汇付RSA公钥加密(加密前4位,加密后最长2048位),[参见参考文档](https://paas.huifu.com/partners/guide/#/api_jiami_jiemi);&lt;br/&gt;&lt;font color&#x3D;&quot;green&quot;&gt;示例值:Ly+fnExeyPO……ebfc6XJXZss&#x3D;&lt;/font&gt;
  650. // $request->setExpiration("test");
  651. // 设备信息域 
  652. // $request->setTrxDeviceInf(getTrxDeviceInf());
  653. // 设置非必填字段
  654. $extendInfoMap = array();
  655. // 商户名称
  656. //$extendInfoMap["merch_name"] = "测试";
  657. // 验卡流水号
  658. $extendInfoMap["trans_id"] = $data['trans_id'];
  659. // 卡的借贷类型
  660. // $extendInfoMap["dc_type"]= "";
  661. // 风控信息
  662. // $extendInfoMap["risk_info"]= getRiskInfo();
  663. $request->setExtendInfo($extendInfoMap);
  664. // 3. 发起API调用
  665. $result = $this->postRequest($request);
  666. if (!$result || $result->isError()) { //失败处理
  667. throw new Exception($result->getErrorInfo());
  668. } else { //成功处理
  669. $resData = $result->getRspDatas();
  670. $resData = $resData['data'];
  671. if ($resData['resp_code'] == '00000000' || $resData['resp_code'] == '00000100') {
  672. return $resData;
  673. }
  674. throw new Exception($resData['resp_desc']);
  675. }
  676. }
  677. /**
  678. * 作者:zengfanhua
  679. * 创建时间:2023/12/28 13:05:32
  680. * 发送快捷支付短信
  681. * @param array data UserBankCard->id
  682. * @throws Exception
  683. * @return bool
  684. */
  685. public function sendPaySms($data, $notify_url, $expireDate, $splitAccount = [])
  686. {
  687. // 2.组装请求参数
  688. $request = new V2TradeOnlinepaymentQuickpayApplyRequest();
  689. // 请求日期
  690. $request->setReqDate(date("Ymd"));
  691. // 请求流水号
  692. $request->setReqSeqId(date("YmdHis") . mt_rand());
  693. // 汇付商户Id
  694. $request->setHuifuId($data['huifu_id']);
  695. // 用户客户号
  696. $request->setUserHuifuId($data['cust_id']);
  697. // 绑卡id
  698. $request->setCardBindId($data['sign_no']);
  699. // 订单金额
  700. $request->setTransAmt($data['amount']);
  701. // 银行扩展字段
  702. $request->setExtendPayData(HuifuFastPayParam::getExtendPayData());
  703. // 安全信息
  704. $request->setRiskCheckData(HuifuFastPayParam::getRiskCheckData());
  705. // 设备数据
  706. $request->setTerminalDeviceData(HuifuFastPayParam::getTerminalDeviceData());
  707. // 异步通知地址
  708. $request->setNotifyUrl($notify_url);
  709. // 设置非必填字段
  710. $extendInfoMap = HuifuFastPayParam::getExtendInfos($splitAccount, $expireDate);
  711. if (!empty($data['delay_acct_flag'])) $extendInfoMap['delay_acct_flag'] = $data['delay_acct_flag'];
  712. $request->setExtendInfo($extendInfoMap);
  713. // 3. 发起API调用
  714. $result = $this->postRequest($request);
  715. if (!$result || $result->isError()) { //失败处理
  716. throw new Exception($result->getErrorInfo());
  717. } else { //成功处理
  718. $resData = $result->getRspDatas();
  719. $resData = $resData['data'];
  720. if ($resData['resp_code'] == '00000000' || $resData['resp_code'] == '00000100') {
  721. return $resData;
  722. }
  723. throw new Exception($resData['resp_desc']);
  724. }
  725. }
  726. /**
  727. * 作者:zengfanhua
  728. * 创建时间:2023/12/28 13:05:32
  729. * 发送快捷支付短信确认
  730. * @param array data UserBankCard->id
  731. * @throws Exception
  732. * @return bool
  733. */
  734. public function sendPaySmsConfirm($data, $notify_url)
  735. {
  736. // 2.组装请求参数
  737. $request = new V2TradeOnlinepaymentQuickpayConfirmRequest();
  738. // 请求日期
  739. $request->setReqDate(date("Ymd"));
  740. // 请求流水号
  741. $request->setReqSeqId($data['order_id']);
  742. // 商户号
  743. $request->setHuifuId($data['huifu_id']);
  744. // 短信验证码
  745. $request->setSmsCode($data['sms_code']);
  746. // 商品描述
  747. $request->setGoodsDesc($data['goods_title']);
  748. // 外部地址
  749. $request->setNotifyUrl($notify_url);
  750. $extendInfoMap = [];
  751. if (!empty($data['delay_acct_flag'])) $extendInfoMap['delay_acct_flag'] = $data['delay_acct_flag'];
  752. // 设置非必填字段
  753. $request->setExtendInfo($extendInfoMap);
  754. // 3. 发起API调用
  755. $result = $this->postRequest($request);
  756. if (!$result || $result->isError()) { //失败处理
  757. throw new Exception($result->getErrorInfo());
  758. } else { //成功处理
  759. $resData = $result->getRspDatas();
  760. $resData = $resData['data'];
  761. if ($resData['resp_code'] == '00000000' || $resData['resp_code'] == '00000100') {
  762. return $resData;
  763. }
  764. throw new Exception($resData['resp_desc']);
  765. }
  766. }
  767. // 单独分账
  768. public function shareCommission($data, $splitAccount)
  769. {
  770. $request = new V2TradePaymentDelaytransConfirmRequest();
  771. // 请求日期
  772. $request->setReqDate(date("Ymd"));
  773. // 请求流水号
  774. $request->setReqSeqId($data['order_id']);
  775. // 商户号
  776. $request->setHuifuId($data['huifu_id']);
  777. // 订单编号
  778. $request->setOrgMerOrdId($data['trade_no']);
  779. $extendInfoMap["acct_split_bunch"] = HuifuPreOrderParam::getAcctSplitBunchRucan($splitAccount);
  780. // 原交易为快捷支付必填:QUICK_PAY,
  781. // 原交易为余额支付必填:ACCT_PAYMENT;
  782. if (!empty($data['pay_type'])) $extendInfoMap["pay_type"] = $data['pay_type'];
  783. // $extendInfoMap['org_mer_ord_id'] = $data['trade_no'];
  784. $extendInfoMap['org_req_date'] = $data['org_req_date'];
  785. $extendInfoMap['org_req_seq_id'] = $data['org_req_seq_id'];
  786. $request->setExtendInfo($extendInfoMap);
  787. // 3. 发起API调用
  788. $result = $this->postRequest($request);
  789. if (!$result || $result->isError()) { //失败处理
  790. // throw new \Exception(is_string($result->getErrorInfo()) ? $result->getErrorInfo() : var_export($result->getErrorInfo(), true));
  791. self::$static_error = !empty($result) ? (is_string($result->getErrorInfo()) ? $result->getErrorInfo() :
  792. var_export($result->getErrorInfo(), true)) : '未获取到响应数据';
  793. return false;
  794. } else { //成功处理
  795. $resData = $result->getRspDatas();
  796. $resData = $resData['data'];
  797. if ($resData['resp_code'] == '00000000' || $resData['resp_code'] == '00000100') {
  798. return $resData;
  799. }
  800. self::$static_error = $resData;
  801. return false;
  802. // throw new \Exception($resData['resp_desc']);
  803. }
  804. }
  805. /**
  806. * 发起post请求,并记录请求日志
  807. *
  808. * @param BaseRequest $request
  809. *
  810. * @return BsPay
  811. */
  812. public function postRequest($request)
  813. {
  814. $client = new BsPayClient();
  815. /** @var $result BsPay */
  816. $result = $client->postRequest($request);
  817. // 写入接口请求日志
  818. try {
  819. if (is_object($result)) {
  820. $logRes = HuifupayPayRequestLog::setData(
  821. $this->mall_id,
  822. [
  823. 'mall_id' => $this->mall_id,
  824. 'url' => $result->getUrl() ?: '',
  825. 'path' => (new ReflectionClass($request))->getShortName(),
  826. 'method' => 'post',
  827. 'request_data' => $result->getReqDatas() ?: [],
  828. 'response_data' => $result->getRspDatas() ?: '',
  829. 'http_state_code' => $result->getHttpStateCode() ?: 0,
  830. 'headers' => $result->getHttpHeaders() ?: [],
  831. 'err_msg' => $result->getErrorInfo() ?: '',
  832. ]
  833. );
  834. if (!$logRes) {
  835. throw new RuntimeException(HuifupayPayRequestLog::getStaticError());
  836. }
  837. $this->requestId = $logRes['id'];
  838. }
  839. }catch (\Exception $e) {
  840. Yii::$app->custom->logs('【汇付】记录请求日志失败', compact('result', 'request'));
  841. }
  842. return $result;
  843. }
  844. }
  845. class HuifuJsPayParam
  846. {
  847. /**
  848. * 作者:zengfanhua
  849. * 创建时间:2023/12/28 13:45:00
  850. * @return array
  851. */
  852. public static function getExtendInfos($notify_url, $wxData = [], $alipayData = [], $expireDate, $splitAccount = [])
  853. {
  854. $extendInfoMap = [];
  855. // 交易有效期
  856. $extendInfoMap["time_expire"] = date('YmdHis', $expireDate);
  857. // 聚合正扫微信拓展参数集合
  858. $extendInfoMap["wx_data"] = $wxData;
  859. // 支付宝扩展参数集合
  860. $extendInfoMap["alipay_data"] = $alipayData;
  861. // 银联参数集合
  862. // $extendInfoMap["unionpay_data"]= getUnionpayData();
  863. // 数字人民币参数集合
  864. // $extendInfoMap["dc_data"]= getDcData();
  865. // 分账对象
  866. $extendInfoMap["acct_split_bunch"] = self::getAcctSplitBunch($splitAccount);
  867. // 传入分帐遇到优惠的处理规则
  868. $extendInfoMap["term_div_coupon_type"] = "0";
  869. // 补贴支付信息
  870. // $extendInfoMap["combinedpay_data"]= getCombinedpayData();
  871. // 账户号
  872. // $extendInfoMap["acct_id"]= "";
  873. // 手续费扣款标志
  874. // $extendInfoMap["fee_flag"]= "";
  875. // 禁用信用卡标记
  876. $extendInfoMap["limit_pay_type"] = "NO_CREDIT";
  877. // 是否延迟交易
  878. $extendInfoMap["delay_acct_flag"] = "N";
  879. // 商户贴息标记
  880. $extendInfoMap["fq_mer_discount_flag"] = "N";
  881. // 渠道号
  882. $extendInfoMap["channel_no"] = "";
  883. // 场景类型
  884. $extendInfoMap["pay_scene"] = "02";
  885. // 安全信息
  886. $extendInfoMap["risk_check_data"] = self::getRiskCheckData();
  887. // 设备信息
  888. $extendInfoMap["terminal_device_data"] = self::getTerminalDeviceData();
  889. // 备注
  890. $extendInfoMap["remark"] = "String";
  891. // 异步通知地址
  892. $extendInfoMap["notify_url"] = $notify_url;
  893. return $extendInfoMap;
  894. }
  895. public static function getGoodsDetailWxRucan()
  896. {
  897. $dto = array();
  898. // 商品编码
  899. // $dto["goods_id"] = "";
  900. // 商品名称
  901. // $dto["goods_name"] = "";
  902. // 商品单价(元)
  903. // $dto["price"] = "";
  904. // 商品数量
  905. // $dto["quantity"] = "";
  906. // 微信侧商品编码
  907. // $dto["wxpay_goods_id"] = "";
  908. $dtoList = array();
  909. array_push($dtoList, $dto);
  910. return $dtoList;
  911. }
  912. public static function getDetail()
  913. {
  914. $dto = array();
  915. // 单品列表
  916. // $dto["goods_detail"] = getGoodsDetailWxRucan();
  917. // 订单原价(元)
  918. // $dto["cost_price"] = "";
  919. // 商品小票ID
  920. // $dto["receipt_id"] = "";
  921. return $dto;
  922. }
  923. public static function getStoreInfo()
  924. {
  925. $dto = array();
  926. // 门店id
  927. // $dto["id"] = "";
  928. // 门店名称
  929. // $dto["name"] = "";
  930. // 门店行政区划码
  931. // $dto["area_code"] = "";
  932. // 门店详细地址
  933. // $dto["ass"] = "";
  934. $dtoList = array();
  935. array_push($dtoList, $dto);
  936. return $dtoList;
  937. }
  938. public static function getSceneInfo()
  939. {
  940. $dto = array();
  941. // 门店信息
  942. // $dto["store_info"] = getStoreInfo();
  943. return $dto;
  944. }
  945. public static function getWxData($mall_id,$open_id,$extra = [])
  946. {
  947. $wechat_config = \Yii::$app->services->pay->getWechatConfig($mall_id);
  948. $dto = array();
  949. // 子商户公众账号id
  950. $dto["sub_appid"] = $wechat_config['mini_program_app_id']??'';
  951. // 用户标识
  952. // $dto["openid"] = "";
  953. // 子商户用户标识
  954. $dto["sub_openid"] = $open_id;
  955. // 附加数据
  956. // $dto["attach"] = "";
  957. // // 商品描述
  958. // $dto["body"] = "";
  959. // // 商品详情
  960. // $dto["detail"] = getDetail();
  961. // // 设备号
  962. // $dto["device_info"] = "";
  963. // // 订单优惠标记
  964. // $dto["goods_tag"] = "";
  965. // // 实名支付
  966. // $dto["identity"] = "";
  967. // // 开发票入口开放标识
  968. // $dto["receipt"] = "";
  969. // // 场景信息
  970. // $dto["scene_info"] = getSceneInfo();
  971. // // 终端ip
  972. // $dto["spbill_create_ip"] = "";
  973. // // 单品优惠标识
  974. // $dto["promotion_flag"] = "";
  975. // // 新增商品ID
  976. // $dto["product_id"] = "";
  977. // // 指定支付者
  978. // $dto["limit_payer"] = "";
  979. return json_encode($dto, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  980. }
  981. public static function getExtendParams()
  982. {
  983. $dto = array();
  984. // 卡类型
  985. // $dto["card_type"] = "";
  986. // // 支付宝点餐场景类型
  987. // $dto["food_order_type"] = "qr_order";
  988. // // 花呗分期数
  989. // $dto["hb_fq_num"] = "";
  990. // // 花呗卖家承担的手续费百分比
  991. // $dto["hb_fq_seller_percent"] = "";
  992. // // 行业数据回流信息
  993. // $dto["industry_reflux_info"] = "String";
  994. // // 停车场id
  995. // $dto["parking_id"] = "123wsx";
  996. // // 系统商编号
  997. // $dto["sys_service_provider_id"] = "1111111";
  998. // 信用卡分期资产方式
  999. // $dto["fq_channels"] = "";
  1000. return $dto;
  1001. }
  1002. public static function getGoodsDetail()
  1003. {
  1004. $dto = array();
  1005. // 商品的编号
  1006. // $dto["goods_id"] = "12312321";
  1007. // // 商品名称(元)
  1008. // $dto["goods_name"] = "阿里";
  1009. // // 商品单价
  1010. // $dto["price"] = "0.01";
  1011. // // 商品数量
  1012. // $dto["quantity"] = "20";
  1013. // // 商品描述信息
  1014. // $dto["body"] = "";
  1015. // // 商品类目树
  1016. // $dto["categories_tree"] = "String";
  1017. // // 商品类目
  1018. // $dto["goods_category"] = "";
  1019. // // 商品的展示地址
  1020. // $dto["show_url"] = "";
  1021. // $dtoList = array();
  1022. // array_push($dtoList, $dto);
  1023. return $dto;
  1024. }
  1025. public static function getExtUserInfo()
  1026. {
  1027. $dto = array();
  1028. // 姓名
  1029. // $dto["name"] = "";
  1030. // 手机号
  1031. // $dto["mobile"] = "";
  1032. // 证件类型
  1033. // $dto["cert_type"] = "";
  1034. // 证件号
  1035. // $dto["cert_no"] = "";
  1036. // 允许的最小买家年龄
  1037. // $dto["min_age"] = "";
  1038. // 是否强制校验付款人身份信息
  1039. // $dto["fix_buyer"] = "";
  1040. // 是否强制校验身份信息
  1041. // $dto["need_check_info"] = "";
  1042. return $dto;
  1043. }
  1044. public static function getAlipayData()
  1045. {
  1046. $dto = array();
  1047. // 买家的支付宝唯一用户号
  1048. $dto["buyer_id"] = "20880414938706770000";
  1049. // 支付宝的店铺编号
  1050. $dto["alipay_store_id"] = "";
  1051. // 买家支付宝账号
  1052. $dto["buyer_logon_id"] = "String";
  1053. // 业务扩展参数
  1054. $dto["extend_params"] = self::getExtendParams();
  1055. // 订单包含的商品列表信息
  1056. $dto["goods_detail"] = self::getGoodsDetail();
  1057. // 商户原始订单号
  1058. $dto["merchant_order_no"] = "String";
  1059. // 商户操作员编号
  1060. $dto["operator_id"] = "123213213";
  1061. // 销售产品码
  1062. $dto["product_code"] = "String";
  1063. // 卖家支付宝用户号
  1064. $dto["seller_id"] = "String";
  1065. // 商户门店编号
  1066. $dto["store_id"] = "";
  1067. // 外部指定买家
  1068. // $dto["ext_user_info"] = getExtUserInfo();
  1069. // 订单标题
  1070. // $dto["subject"] = "";
  1071. // 商家门店名称
  1072. // $dto["store_name"] = "";
  1073. return json_encode($dto, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  1074. }
  1075. public static function getPayeeInfo()
  1076. {
  1077. $dto = array();
  1078. // 商户类别
  1079. // $dto["mer_cat_code"] = "";
  1080. // 二级商户代码
  1081. // $dto["sub_id"] = "";
  1082. // 二级商户名称
  1083. // $dto["sub_name"] = "";
  1084. // 终端号
  1085. // $dto["term_id"] = "";
  1086. return $dto;
  1087. }
  1088. public static function getUnionpayData()
  1089. {
  1090. $dto = array();
  1091. // 收款方附加数据
  1092. // $dto["acq_addn_data"] = "";
  1093. // 地区信息
  1094. // $dto["area_info"] = "";
  1095. // 持卡人ip
  1096. // $dto["customer_ip"] = "";
  1097. // 前台通知地址
  1098. // $dto["front_url"] = "";
  1099. // 订单描述
  1100. // $dto["order_desc"] = "";
  1101. // 收款方附言
  1102. // $dto["payee_comments"] = "";
  1103. // 收款方信息
  1104. // $dto["payee_info"] = getPayeeInfo();
  1105. // 银联分配的服务商机构标识码
  1106. // $dto["pnr_ins_id_cd"] = "";
  1107. // 请求方自定义域
  1108. // $dto["req_reserved"] = "";
  1109. // 终端信息
  1110. // $dto["term_info"] = "";
  1111. // 云闪付用户标识
  1112. // $dto["user_id"] = "";
  1113. return json_encode($dto, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  1114. }
  1115. public static function getDcData()
  1116. {
  1117. $dto = array();
  1118. // 数字货币银行编号
  1119. // $dto["digital_bank_no"] = "";
  1120. return json_encode($dto, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  1121. }
  1122. public static function getAcctInfosRucan($splitAccount)
  1123. {
  1124. $dtoList = array();
  1125. foreach ($splitAccount as $key => $value) {
  1126. $dto = array();
  1127. // 分账金额
  1128. $dto["div_amt"] = $value['num'];
  1129. // 被分账方ID
  1130. $dto["huifu_id"] = $value['id'];
  1131. // 账户号
  1132. $dto["acct_id"] = "";
  1133. array_push($dtoList, $dto);
  1134. }
  1135. return $dtoList;
  1136. }
  1137. public static function getAcctSplitBunch($splitAccount)
  1138. {
  1139. $dto = array();
  1140. if (empty($splitAccount)) {
  1141. return $dto;
  1142. }
  1143. // 分账明细
  1144. $dto["acct_infos"] = self::getAcctInfosRucan($splitAccount);
  1145. return json_encode($dto, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  1146. }
  1147. public static function getCombinedpayData()
  1148. {
  1149. $dto = array();
  1150. // 补贴方汇付编号
  1151. // $dto["huifu_id"] = "test";
  1152. // 补贴方类型
  1153. // $dto["user_type"] = "test";
  1154. // 补贴方账户号
  1155. // $dto["acct_id"] = "test";
  1156. // 补贴金额
  1157. // $dto["amount"] = "test";
  1158. $dtoList = array();
  1159. array_push($dtoList, $dto);
  1160. return json_encode($dtoList, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  1161. }
  1162. public static function getRiskCheckData()
  1163. {
  1164. $dto = array();
  1165. // ip地址
  1166. $dto["ip_addr"] = "180.167.105.130";
  1167. // 基站地址
  1168. $dto["base_station"] = "192.168.1.1";
  1169. // 纬度
  1170. $dto["latitude"] = "33.3";
  1171. // 经度
  1172. $dto["longitude"] = "33.3";
  1173. return json_encode($dto, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  1174. }
  1175. public static function getTerminalDeviceData()
  1176. {
  1177. $dto = array();
  1178. // 商户设备类型
  1179. // $dto["mer_device_type"] = "test";
  1180. // 汇付机具号
  1181. $dto["devs_id"] = "SPINTP357338300264411";
  1182. // 设备类型
  1183. $dto["device_type"] = "1";
  1184. // 交易设备IP
  1185. $dto["device_ip"] = "10.10.0.1";
  1186. // 交易设备MAC
  1187. $dto["device_mac"] = "";
  1188. // 交易设备IMEI
  1189. $dto["device_imei"] = "";
  1190. // 交易设备IMSI
  1191. $dto["device_imsi"] = "";
  1192. // 交易设备ICCID
  1193. $dto["device_icc_id"] = "";
  1194. // 交易设备WIFIMAC
  1195. $dto["device_wifi_mac"] = "";
  1196. // 交易设备GPS
  1197. $dto["device_gps"] = "192.168.0.0";
  1198. // 商户终端应用程序版本
  1199. // $dto["app_version"] = "";
  1200. // SIM 卡卡号
  1201. // $dto["icc_id"] = "";
  1202. // 商户终端实时经纬度信息
  1203. // $dto["location"] = "";
  1204. // 商户交易设备IP
  1205. // $dto["mer_device_ip"] = "";
  1206. // 移动国家代码
  1207. // $dto["mobile_country_cd"] = "";
  1208. // 移动网络号码
  1209. // $dto["mobile_net_num"] = "";
  1210. // 商户终端入网认证编号
  1211. // $dto["network_license"] = "";
  1212. // 商户终端序列号
  1213. // $dto["serial_num"] = "";
  1214. return json_encode($dto, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  1215. }
  1216. }
  1217. class HuifuSignParam
  1218. {
  1219. /**
  1220. * 非必填字段
  1221. *
  1222. */
  1223. public static function getExtendInfos()
  1224. {
  1225. // 设置非必填字段
  1226. $extendInfoMap = array();
  1227. // 商户名称
  1228. //$extendInfoMap["merch_name"] = "全球鹰(浙江)网络科技有限公司";
  1229. // 电子邮箱
  1230. //$extendInfoMap["email"] = "290475886@qq.com";
  1231. // 卡的借贷类型
  1232. // $extendInfoMap["dc_type"]= "";
  1233. // 风控信息
  1234. // $extendInfoMap["risk_info"]= getRiskInfo();
  1235. return $extendInfoMap;
  1236. }
  1237. }
  1238. class HuifuPreOrderParam
  1239. {
  1240. /**
  1241. * 非必填字段
  1242. *
  1243. */
  1244. public static function getExtendInfos($expireDate, $notify_url, $splitAccount)
  1245. {
  1246. // 设置非必填字段
  1247. $extendInfoMap = array();
  1248. // 收银台ID
  1249. $extendInfoMap["checkout_id"] = "";
  1250. // 是否延迟交易
  1251. $extendInfoMap["delay_acct_flag"] = "N";
  1252. // 分账对象
  1253. $extendInfoMap["acct_split_bunch"] = self::getAcctSplitBunchRucan($splitAccount);
  1254. // 交易失效时间
  1255. $extendInfoMap["time_expire"] = date('YmdHis', $expireDate);
  1256. // 业务信息
  1257. // $extendInfoMap["biz_info"]= getBizInfo();
  1258. // 交易异步通知地址
  1259. $extendInfoMap["notify_url"] = $notify_url;
  1260. return $extendInfoMap;
  1261. }
  1262. public static function getAcctInfosRucan($accountList)
  1263. {
  1264. $dtoList = array();
  1265. foreach ($accountList as $key => $value) {
  1266. $dto = array();
  1267. //分账金额
  1268. $dto["div_amt"] = $value['num'];
  1269. // 被分账方ID
  1270. $dto["huifu_id"] = $value['id'];
  1271. array_push($dtoList, $dto);
  1272. }
  1273. return $dtoList;
  1274. }
  1275. public static function getAcctSplitBunchRucan($accountList)
  1276. {
  1277. $dto = array();
  1278. if (empty($accountList)) {
  1279. return $dto;
  1280. }
  1281. // 分账明细
  1282. $dto["acct_infos"] = self::getAcctInfosRucan($accountList);
  1283. return json_encode($dto, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  1284. }
  1285. public static function getMiniappDataRucan()
  1286. {
  1287. $dto = array();
  1288. // 是否生成scheme_code
  1289. $dto["need_scheme"] = "N"; // 之前是Y
  1290. // 应用ID
  1291. $dto["seq_id"] = "";
  1292. // 私有信息
  1293. $dto["private_info"] = "oppsHosting://";
  1294. return $dto;
  1295. //return json_encode($dto, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  1296. }
  1297. public static function getPayCheckWx()
  1298. {
  1299. $dto = array();
  1300. // 指定支付者
  1301. // $dto["limit_payer"] = "";
  1302. // 微信实名验证
  1303. // $dto["real_name_flag"] = "";
  1304. return $dto;
  1305. }
  1306. public static function getPersonPayer()
  1307. {
  1308. $dto = array();
  1309. // 姓名
  1310. // $dto["name"] = "";
  1311. // 证件类型
  1312. // $dto["cert_type"] = "";
  1313. // 证件号
  1314. // $dto["cert_no"] = "";
  1315. return $dto;
  1316. }
  1317. public function getBizInfo()
  1318. {
  1319. $dto = array();
  1320. // 付款人验证(微信)
  1321. // $dto["payer_check_wx"] = getPayCheckWx();
  1322. // 个人付款人信息
  1323. // $dto["person_payer"] = getPersonPayer();
  1324. return json_encode($dto, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  1325. }
  1326. }
  1327. class HuifuRefundParam
  1328. {
  1329. /**
  1330. * 非必填字段
  1331. *
  1332. */
  1333. public static function getExtendInfos($org_req_seq_id, $splitAccount = [])
  1334. {
  1335. // 设置非必填字段
  1336. $extendInfoMap = array();
  1337. // 原交易全局流水号
  1338. //$extendInfoMap["org_hf_seq_id"] = '';
  1339. // 原交易微信支付宝的商户单号
  1340. // $extendInfoMap["org_party_order_id"]= "";
  1341. // 原交易请求流水号
  1342. $extendInfoMap["org_req_seq_id"]= $org_req_seq_id;
  1343. // 分账对象
  1344. $extendInfoMap["acct_split_bunch"] = self::getAcctSplitBunchRucan($splitAccount);
  1345. // 聚合正扫微信拓展参数集合
  1346. // $extendInfoMap["wx_data"]= self::getWxData();
  1347. // 数字货币扩展参数集合
  1348. // $extendInfoMap["digital_currency_data"]= self::getDigitalCurrencyData();
  1349. // 补贴支付信息
  1350. // $extendInfoMap["combinedpay_data"]= self::getCombinedpayData();
  1351. // 备注
  1352. // $extendInfoMap["remark"]= "";
  1353. // 是否垫资退款
  1354. // $extendInfoMap["loan_flag"]= "";
  1355. // 垫资承担者
  1356. // $extendInfoMap["loan_undertaker"]= "";
  1357. // 垫资账户类型
  1358. // $extendInfoMap["loan_acct_type"]= "";
  1359. // 安全信息
  1360. // $extendInfoMap["risk_check_data"]= self::getRiskCheckData();
  1361. // 设备信息
  1362. // $extendInfoMap["terminal_device_data"]= self::getTerminalDeviceData();
  1363. // 异步通知地址
  1364. // $extendInfoMap["notify_url"]= "";
  1365. return $extendInfoMap;
  1366. }
  1367. public static function getAcctInfosRucan($splitAccount)
  1368. {
  1369. $dtoList = array();
  1370. foreach ($splitAccount as $key => $value) {
  1371. $dto = array();
  1372. // 分账金额
  1373. $dto["div_amt"] = $value['num'];
  1374. // 被分账方ID
  1375. $dto["huifu_id"] = $value['id'];
  1376. // 账户号
  1377. $dto["acct_id"] = "";
  1378. array_push($dtoList, $dto);
  1379. }
  1380. return $dtoList;
  1381. }
  1382. public static function getAcctSplitBunchRucan($splitAccount)
  1383. {
  1384. $dto = array();
  1385. if (empty($splitAccount)) {
  1386. return $dto;
  1387. }
  1388. // 分账信息列表
  1389. $dto["acct_infos"] = self::getAcctInfosRucan($splitAccount);
  1390. return json_encode($dto, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  1391. }
  1392. public static function getGoodsDetail()
  1393. {
  1394. $dto = array();
  1395. // 商品编码
  1396. // $dto["goods_id"] = "test";
  1397. // 优惠退款金额
  1398. // $dto["refund_amount"] = "test";
  1399. // 商品退货数量
  1400. // $dto["refund_quantity"] = "test";
  1401. // 商品单价
  1402. // $dto["price"] = "test";
  1403. $dtoList = array();
  1404. array_push($dtoList, $dto);
  1405. return $dtoList;
  1406. }
  1407. public static function getDetail()
  1408. {
  1409. $dto = array();
  1410. // 商品详情列表
  1411. // $dto["goods_detail"] = getGoodsDetail();
  1412. return $dto;
  1413. }
  1414. public static function getWxData()
  1415. {
  1416. $dto = array();
  1417. // 退款商品详情
  1418. // $dto["detail"] = getDetail();
  1419. return $dto;
  1420. }
  1421. public static function getDigitalCurrencyData()
  1422. {
  1423. $dto = array();
  1424. // 退款原因
  1425. // $dto["refund_desc"] = "";
  1426. return json_encode($dto, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  1427. }
  1428. public static function getCombinedpayData()
  1429. {
  1430. $dto = array();
  1431. // 补贴方汇付编号
  1432. // $dto["huifu_id"] = "test";
  1433. // 补贴方类型
  1434. // $dto["user_type"] = "test";
  1435. // 补贴方账户号
  1436. // $dto["acct_id"] = "test";
  1437. // 补贴金额
  1438. // $dto["amount"] = "test";
  1439. $dtoList = array();
  1440. array_push($dtoList, $dto);
  1441. return json_encode($dtoList, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  1442. }
  1443. public static function getRiskCheckData()
  1444. {
  1445. $dto = array();
  1446. // ip地址
  1447. // $dto["ip_addr"] = "";
  1448. // 基站地址
  1449. // $dto["base_station"] = "";
  1450. // 纬度
  1451. // $dto["latitude"] = "";
  1452. // 经度
  1453. // $dto["longitude"] = "";
  1454. return json_encode($dto, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  1455. }
  1456. public static function getTerminalDeviceData()
  1457. {
  1458. $dto = array();
  1459. // 设备类型
  1460. // $dto["device_type"] = "";
  1461. // 交易设备IP
  1462. // $dto["device_ip"] = "";
  1463. // 交易设备MAC
  1464. // $dto["device_mac"] = "";
  1465. // 交易设备IMEI
  1466. // $dto["device_imei"] = "";
  1467. // 交易设备IMSI
  1468. // $dto["device_imsi"] = "";
  1469. // 交易设备ICCID
  1470. // $dto["device_icc_id"] = "";
  1471. // 交易设备WIFIMAC
  1472. // $dto["device_wifi_mac"] = "";
  1473. // 交易设备GPS
  1474. // $dto["device_gps"] = "";
  1475. return json_encode($dto, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  1476. }
  1477. }