TestController.php 13 KB

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