TestController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\sj\services\MerchantService;
  4. use bizGhs\express\services\DadaExpressServices;
  5. use bizGhs\order\classes\OrderClass;
  6. use bizHd\message\classes\InformAdminClass;
  7. use bizHd\order\services\OrderService;
  8. use bizHd\wx\classes\WxOpenClass;
  9. use bizGhs\express\services\MiniExpressService;
  10. use common\components\dict;
  11. use common\components\lakala\Lakala;
  12. use common\components\miniUtil;
  13. use common\components\orderSn;
  14. use common\components\wxUtil;
  15. use Yii;
  16. use common\components\util;
  17. class TestController extends BaseController
  18. {
  19. public $guestAccess = ['inform', 'notice', 'order-query', 'add-order', 'index'];
  20. public function actionAliRun()
  21. {
  22. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  23. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  24. $arr = [
  25. ['name' => '国兰花尚', 'merchantNo' => '82239305992006L', 'wx' => [600913569, 600907053], 'zfb' => '2088820709029782']
  26. ];
  27. $new = [];
  28. foreach ($arr as $item) {
  29. $wx = $item['wx'];
  30. $zfb = $item['zfb'];
  31. $name = $item['name'];
  32. $merchantNo = $item['merchantNo'];
  33. $group = [];
  34. foreach ($wx as $oneWx) {
  35. $params = [
  36. 'appid' => 'OP00002119',
  37. 'serial_no' => '018b08cfddbd',
  38. 'merchant_no' => $merchantNo,
  39. 'term_no' => 'C6337694',
  40. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  41. 'lklCertificatePath' => $lklCertificatePath,
  42. ];
  43. $data = [
  44. 'subMerchantId' => $oneWx,
  45. 'tradeMode' => 'WECHAT',
  46. ];
  47. $laResource = new Lakala($params);
  48. $response = $laResource->openStateQuery($data);
  49. $statusName = '出错了';
  50. if ($response['retCode'] == '000000') {
  51. $checkResult = $response['respData']['checkResult'] ?? '';
  52. $statusName = '未授权';
  53. if ($checkResult == 'AUTHORIZE_STATE_AUTHORIZED ') {
  54. $statusName = '已授权';
  55. }
  56. }
  57. $group[] = '微信 ' . $oneWx . ' ' . $statusName;
  58. }
  59. $params = [
  60. 'appid' => 'OP00002119',
  61. 'serial_no' => '018b08cfddbd',
  62. 'merchant_no' => $merchantNo,
  63. 'term_no' => 'C6337694',
  64. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  65. 'lklCertificatePath' => $lklCertificatePath,
  66. ];
  67. $data = [
  68. 'subMerchantId' => $zfb,
  69. 'tradeMode' => 'ALIPAY',
  70. ];
  71. $laResource = new Lakala($params);
  72. $response = $laResource->openStateQuery($data);
  73. $statusName = '出错了';
  74. if ($response['retCode'] == '000000') {
  75. $checkResult = $response['respData']['checkResult'] ?? '';
  76. $statusName = '未授权';
  77. if ($checkResult == 'AUTHORIZE_STATE_AUTHORIZED ') {
  78. $statusName = '已授权';
  79. }
  80. }
  81. $group[] = '支付宝 ' . $zfb . ' ' . $statusName;
  82. $new[] = ['name' => $name, 'status' => $group];
  83. }
  84. print_r($new);
  85. }
  86. public function actionAliRun2()
  87. {
  88. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  89. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  90. $params = [
  91. 'appid' => 'OP00002119',
  92. 'serial_no' => '018b08cfddbd',
  93. 'merchant_no' => '82240505992000N',
  94. 'term_no' => 'C6337694',
  95. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  96. 'lklCertificatePath' => $lklCertificatePath,
  97. ];
  98. $outTradeNo = orderSn::getPurchaseSn();
  99. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  100. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  101. $aliParams = [
  102. 'orderSn' => $outTradeNo,
  103. 'amount' => 0.16,
  104. 'capitalType' => $currentCapitalType,
  105. 'notifyUrl' => $notifyUrl,
  106. ];
  107. $laResource = new Lakala($params);
  108. $response = $laResource->driveAliPay($aliParams);
  109. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  110. echo '<pre>';
  111. echo "下单成功<br/>";
  112. print_r($response);
  113. } else {
  114. echo '<pre>';
  115. echo "下单失败<br/>";
  116. print_r($response);
  117. }
  118. }
  119. public function actionAliRun3()
  120. {
  121. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  122. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  123. $params = [
  124. 'appid' => 'OP00002119',
  125. 'serial_no' => '018b08cfddbd',
  126. 'merchant_no' => '82240505992000N',
  127. 'term_no' => 'C6337694',
  128. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  129. 'lklCertificatePath' => $lklCertificatePath,
  130. ];
  131. $laResource = new Lakala($params);
  132. $outTradeNo = orderSn::getPurchaseSn();
  133. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  134. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  135. $wxParams = [
  136. 'orderSn' => $outTradeNo,
  137. 'amount' => 0.16,
  138. 'capitalType' => $currentCapitalType,
  139. 'notifyUrl' => $notifyUrl,
  140. ];
  141. $response = $laResource->driveWxPay($wxParams);
  142. if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
  143. echo '<pre>';
  144. echo "下单成功<br/>";
  145. print_r($response);
  146. } else {
  147. echo '<pre>';
  148. echo "下单失败<br/>";
  149. print_r($response);
  150. }
  151. }
  152. //dada 城市code
  153. public function actionDadaCityCode()
  154. {
  155. $res = dada::getCityCode(0);
  156. util::success($res);
  157. }
  158. //理由
  159. public function actionDadaReasons()
  160. {
  161. $res = dada::getCancelReason(0);
  162. util::success($res);
  163. }
  164. //达达 :下单
  165. public function actionDadaAddOrder()
  166. {
  167. $orderSn = 'XSD_CS26316851';
  168. $orderInfo = OrderClass::getByOrderSn($orderSn);
  169. $res = DadaExpressServices::addOrder($orderInfo);
  170. util::success($res);
  171. }
  172. //重发快递
  173. public function actionDadaReAdd()
  174. {
  175. $orderSn = 'XSD_CS26316851';
  176. $orderInfo = OrderClass::getByOrderSn($orderSn);
  177. $res = DadaExpressServices::reAddOrder($orderInfo);
  178. util::success($res);
  179. }
  180. //达达状态查询
  181. public function actionDadaOrderStatus()
  182. {
  183. $orderSn = 'XSD_CS26316851';
  184. $res = DadaExpressServices::statusOrder($orderSn);
  185. util::success($res);
  186. }
  187. //达达取消下单
  188. public function actionDadaCancelOrder()
  189. {
  190. $orderSn = 'XSD_CS26316851';
  191. $res = DadaExpressServices::cancelOrder($orderSn, 1);
  192. util::success($res);
  193. }
  194. //获取已支持的配送公司列表接口
  195. public function actionGetAllDelivery()
  196. {
  197. $data = MiniExpressService::getAllImmeDelivery();
  198. util::success($data);
  199. }
  200. //即时配送
  201. /*
  202. * Array
  203. (
  204. [resultcode] => 0
  205. [resultmsg] => OK
  206. [shop_list] => Array
  207. (
  208. [0] => Array
  209. (
  210. [shopid] => 1588714266
  211. [delivery_id] => SFTC
  212. [audit_result] => 0
  213. [create_time] => 1612172838
  214. [remark] =>
  215. [delivery_name] => 顺丰同城急送
  216. )
  217. )
  218. )
  219. */
  220. public function actionGetBindAccount()
  221. {
  222. $merchant = WxOpenClass::getGhsWxInfo();
  223. $isOpen = 2;
  224. $r = miniUtil::getBindAccount($merchant, $isOpen);
  225. dd($r);
  226. }
  227. //下单 (沙箱)
  228. /**
  229. * Array
  230. * (
  231. * [resultcode] => 0
  232. * [resultmsg] => ok
  233. * [fee] => 10
  234. * [waybill_id] => test_shop_id1612365974_waybillid
  235. * [order_status] => 101
  236. * [dispatch_duration] => 300
  237. * )
  238. */
  239. public function actionCreateWaybill()
  240. {
  241. $merchant = WxOpenClass::getGhsWxInfo();
  242. $isOpen = 2;
  243. $shopId = 'test_shop_id';
  244. $shopOrderId = 'test_shop_id' . time();
  245. $appSecret = 'test_app_secrect';
  246. $data = [
  247. 'shopid' => $shopId,
  248. 'shop_order_id' => $shopOrderId,
  249. 'shop_no' => '1',
  250. 'delivery_sign' => miniUtil::getDeliverySign($shopId, $shopOrderId, $appSecret), //,则delivery_sign=SHA1(shopid + shop_order_id + AppSecret)
  251. 'delivery_id' => "TEST",
  252. 'openid' => 'oGKMp45YLxewOTWEbpMFzWoVqdW0',
  253. 'sender' => [
  254. 'name' => 'test',
  255. 'city' => '厦门市',
  256. 'address' => '思明区',
  257. 'address_detail' => '软件园二期',
  258. 'phone' => '19959271111',
  259. 'lng' => 118.134343,
  260. 'lat' => 24.483566,
  261. 'coordinate_type' => 0,
  262. ],
  263. 'receiver' => [
  264. 'name' => 'test',
  265. 'city' => '厦门市',
  266. 'address' => '思明区',
  267. 'address_detail' => '软件园二期',
  268. 'phone' => '19959271111',
  269. 'lng' => 118.134343,
  270. 'lat' => 24.493566,
  271. 'coordinate_type' => 0,
  272. ],
  273. 'cargo' => [
  274. 'goods_value' => 1,
  275. 'goods_weight' => 0.1,
  276. 'cargo_first_class' => '鲜花',
  277. 'cargo_second_class' => '鲜花',
  278. ],
  279. 'order_info' => [
  280. 'order_type' => 0,
  281. ],
  282. 'shop' => [
  283. 'wxa_path' => '/shop',
  284. 'img_url' => 'http://www.baidu.com/test.png',
  285. 'goods_name' => 'test',
  286. 'goods_count' => 1,
  287. ],
  288. ];
  289. $r = miniUtil::addOrder($data, $merchant, $isOpen);
  290. dd($r);
  291. }
  292. //获取运单数据
  293. /**
  294. * Array
  295. * (
  296. * [resultcode] => 0
  297. * [resultmsg] => ok
  298. * [order_status] => 101
  299. * [agent_info] => Array
  300. * (
  301. * )
  302. *
  303. * [waybill_id] => test_shop_id1612365974_waybillid
  304. * [rider_name] =>
  305. * [rider_phone] =>
  306. * [order_token] => NsXweKCKhSyAEIhAdnX3TYZsVDES0-t-tymHDONG0MpRsF31dQvVxiP_JJvLFaKS-kwXuOG3D0hzKkl7o-gzew
  307. * )
  308. */
  309. public function actionGetOrder()
  310. {
  311. $shopId = 'test_shop_id';
  312. $shopOrderId = 'test_shop_id1612365974';
  313. $appSecret = 'test_app_secrect';
  314. $merchant = WxOpenClass::getGhsWxInfo();
  315. $isOpen = 2;
  316. $data = [
  317. 'shopid' => $shopId,
  318. 'shop_order_id' => $shopOrderId,
  319. 'shop_no' => '1',
  320. 'delivery_sign' => MiniExpressService::getDeliverySign($shopId, $shopOrderId, $appSecret),
  321. ];
  322. $r = miniUtil::getOrder($data, $merchant, $isOpen);
  323. dd($r);
  324. }
  325. //沙盒 更新快递状态
  326. public function actionMockUpdateOrder()
  327. {
  328. $merchant = WxOpenClass::getGhsWxInfo();
  329. $isOpen = 2;
  330. /**
  331. * {
  332. * "shopid": "test_shop_id",
  333. * "shop_order_id": "xxxxxxxxxxx",
  334. * "waybill_id": "xxxxxxxxxxxxx",
  335. * "action_time": 12345678,
  336. * "order_status": 101,
  337. * "action_msg": "",
  338. * }
  339. */
  340. $shopId = 'test_shop_id';
  341. $shopOrderId = 'test_shop_id1612365974';
  342. $data = [
  343. 'shop_order_id' => $shopOrderId,
  344. "shopid" => $shopId,
  345. "action_time" => time(),
  346. "order_status" => 302,
  347. 'action_msg' => '状态变更',
  348. ];
  349. $r = miniUtil::mockUpdateOrder($data, $merchant, $isOpen);
  350. dd($r);
  351. }
  352. public function actionTest()
  353. {
  354. }
  355. //新增订单
  356. public function actionAddOrder()
  357. {
  358. $dada = Yii::getAlias("@vendor/dada/");
  359. require_once $dada . 'api/addOrderApi.php';
  360. require_once $dada . 'client/dadaRequestClient.php';
  361. require_once $dada . 'client/dadaResponse.php';
  362. require_once $dada . 'config/config.php';
  363. require_once $dada . 'model/orderModel.php';
  364. // isOnline 判断是否是测试环境,会有不同的域名等
  365. $isOnline = false;
  366. $sourceId = 1000000;
  367. // 初始化一个config
  368. $config = new \Config($sourceId, $isOnline);
  369. $orderModel = new \OrderModel();
  370. $orderModel->setShopNo('11047059');
  371. $orderModel->setOriginId('2018091100000002');
  372. $orderModel->setCityCode('021');
  373. $orderModel->setCargoPrice(10);
  374. $orderModel->setIsPrepay(0);
  375. $orderModel->setReceiverName('测试达达');
  376. $orderModel->setReceiverAddress('上海市崇明岛');
  377. $orderModel->setReceiverLat(31.63);
  378. $orderModel->setReceiverLng(121.41);
  379. $orderModel->setReceiverPhone('18588888888');
  380. $orderModel->setCallback('http://api.b.huaml.com/data/request');
  381. // api主要有2个参数,一个是url, 一个是业务参数
  382. $addOrderApi = new \AddOrderApi(json_encode($orderModel));
  383. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  384. $resp = $dada_client->makeRequest();
  385. echo json_encode($resp);
  386. }
  387. //订单详情查询
  388. public function actionOrderQuery()
  389. {
  390. $dada = Yii::getAlias("@vendor/dada/");
  391. require_once $dada . 'api/OrderQueryApi.php';
  392. require_once $dada . 'client/dadaRequestClient.php';
  393. require_once $dada . 'client/dadaResponse.php';
  394. require_once $dada . 'config/config.php';
  395. require_once $dada . 'model/orderModel.php';
  396. // isOnline 判断是否是测试环境,会有不同的域名等
  397. $isOnline = false;
  398. $sourceId = 1000000;
  399. // 初始化一个config
  400. $config = new \Config($sourceId, $isOnline);
  401. $orderModel = new \OrderModel();
  402. $orderModel->setOrderId('2018091100000002');
  403. // api主要有2个参数,一个是url, 一个是业务参数
  404. $addOrderApi = new \OrderQueryApi(json_encode($orderModel));
  405. $dada_client = new \DadaRequestClient($config, $addOrderApi);
  406. $resp = $dada_client->makeRequest();
  407. echo json_encode($resp);
  408. }
  409. public function actionFocus()
  410. {
  411. $name = '花卉宝';
  412. if (getenv('YII_ENV') == 'dev') {
  413. $name = '花美灵';
  414. }
  415. $merchant = MerchantService::getByCondition(['name' => $name]);
  416. $list = wxUtil::getSubscribeUserList($merchant);
  417. dd($list);
  418. }
  419. //宝贝售出提醒 ssh 2020.1.30
  420. public function actionInform()
  421. {
  422. $merchant = MerchantService::getMerchantById(12362);
  423. $order = OrderService::getById(214810);
  424. InformAdminClass::sendComplete($order);
  425. }
  426. public function actionNotice()
  427. {
  428. $data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
  429. $producer = Yii::$app->rabbitmq->getProducer('informProducer');
  430. echo '<pre>';
  431. print_r($data);
  432. $msg = serialize($data);
  433. $r = $producer->publish($msg, 'informExchange', 'informRoute');
  434. }
  435. }