广州凡科互联网科技有限公司

营业时间
MON-SAT 9:00-18:00

全国服务热线
18720358503

公司门店地址
广州市海珠区工业大道北67号凤凰创意园

电子商务网站定单同歩到內部系统软件构架

日期:2021-04-02 浏览:

电子商务网站的定单如何同歩到企业內部系统软件,以前的作法,网站下完单便会有电子邮件发至在线客服的电子邮箱,电子邮件內容中包括了定单号,以内部系统软件中黏贴定单号从网站在获得订单详情,假如定单撤销了,也是依据电子邮件,来撤销內部系统软件的定单,这类半全自动的方法還是较为不便,常常在线客服漏看过电子邮件,定单进不上內部系统软件后边的配货送货危害时效性,对客户感受不太好。
方法改善以后
根据rabbitma序列来解决,付款以后把订单详情载入到序列里边,內部系统软件写一个php脚本制作不断的去跑,那样时效性的文档处理了,都不会产生漏单的状况,系统软件升级也较为立即。
下边是序列的关键编码案例

 ?php 
 * amqp协议书实际操作类,能够浏览rabbitMQ 
 * 先要安裝php_amqp拓展 
class RabbitMQCommand{ 
 public $configs = array(); 
 //互换机名字 
 public $exchange_name = ''; 
 //序列名字 
 public $queue_name = ''; 
 //路由器名字 
 public $route_key = ''; 
 * 长久化,默认设置True 
 public $durable = True; 
 * 全自动删掉 
 * exchange is deleted when all queues have finished using it 
 * queue is deleted when last consumer unsubscribes 
 public $autodelete = False; 
 * 镜像系统 
 * 镜像系统序列,开启后信息会在连接点中间拷贝,有master和slave的定义 
 public $mirror = False; 
 private $_conn = Null; 
 private $_exchange = Null; 
 private $_channel = Null; 
 private $_queue = Null; 
 * @configs array('host'= $host,'port'= 5672,'username'= $username,'password'= $password,'vhost'= '/') 
 public function __construct($configs = array(), $exchange_name = '', $queue_name = '', $route_key = '') { 
 $this- setConfigs($configs); 
 $this- exchange_name = $exchange_name; 
 $this- queue_name = $queue_name; 
 $this- route_key = $route_key; 
 private function setConfigs($configs) { 
 if (!is_array($configs)) { 
 throw new Exception('configs is not array'); 
 if (!($configs['host'] $configs['port'] $configs['username'] $configs['password'])) { 
 throw new Exception('configs is empty'); 
 if (empty($configs['vhost'])) { 
 $configs['vhost'] = '/'; 
 $configs['login'] = $configs['username']; 
 unset($configs['username']); 
 $this- configs = $configs; 
 * 设定是不是长久化,默认设置为True 
 public function setDurable($durable) { 
 $this- durable = $durable; 
 * 设定是不是全自动删掉 
 public function setAutoDelete($autodelete) { 
 $this- autodelete = $autodelete; 
 * 设定是不是镜像系统 
 public function setMirror($mirror) { 
 $this- mirror = $mirror; 
 * 开启amqp联接 
 private function open() { 
 if (!$this- _conn) { 
 try { 
 $this- _conn = new AMQPConnection($this- configs); 
 $this- _conn- connect(); 
 $this- initConnection(); 
 } catch (AMQPConnectionException $ex) { 
 throw new Exception('cannot connection rabbitmq',500); 
 * rabbitmq联接不会改变 
 * 重设互换机,序列,路由器等配备 
 public function reset($exchange_name, $queue_name, $route_key) { 
 $this- exchange_name = $exchange_name; 
 $this- queue_name = $queue_name; 
 $this- route_key = $route_key; 
 $this- initConnection(); 
 * 原始化rabbit联接的有关配备 
 private function initConnection() { 
 if (empty($this- exchange_name) || empty($this- queue_name) || empty($this- route_key)) { 
 throw new Exception('rabbitmq exchange_name or queue_name or route_key is empty',500); 
 $this- _channel = new AMQPChannel($this- _conn); 
 $this- _exchange = new AMQPExchange($this- _channel); 
 $this- _exchange- setName($this- exchange_name); 
 $this- _exchange- setType(AMQP_EX_TYPE_DIRECT); 
 if ($this- durable) 
 $this- _exchange- setFlags(AMQP_DURABLE); 
 if ($this- autodelete) 
 $this- _exchange- setFlags(AMQP_AUTODELETE); 
 $this- _exchange- declare(); 
 $this- _queue = new AMQPQueue($this- _channel); 
 $this- _queue- setName($this- queue_name); 
 if ($this- durable) 
 $this- _queue- setFlags(AMQP_DURABLE); 
 if ($this- autodelete) 
 $this- _queue- setFlags(AMQP_AUTODELETE); 
 if ($this- mirror) 
 $this- _queue- setArgument('x-ha-policy', 'all'); 
 $this- _queue- declare(); 
 $this- _queue- bind($this- exchange_name, $this- route_key); 
 public function close() { 
 if ($this- _conn) { 
 $this- _conn- disconnect(); 
 public function __sleep() { 
 $this- close(); 
 return array_keys(get_object_vars($this)); 
 public function __destruct() { 
 $this- close(); 
 * 生产制造者推送信息 
 public function send($msg) { 
 $this- open(); 
 if(is_array($msg)){ 
 $msg = json_encode($msg); 
 }else{ 
 $msg = trim(strval($msg)); 
 return $this- _exchange- publish($msg, $this- route_key); 
 * 消費者 
 * $fun_name = array($classobj,$function) or function name string 
 * $autoack 是不是全自动回复 
 * function processMessage($envelope, $queue) { 
 $msg = $envelope- getBody(); 
 echo $msg."\n"; //解决信息 
 $queue- ack($envelope- getDeliveryTag());//手动式回复 
 public function run($fun_name, $autoack = True){ 
 $this- open(); 
 if (!$fun_name || !$this- _queue) return False; 
 while(True){ 
 if ($autoack) $this- _queue- consume($fun_name, AMQP_AUTOACK); 
 else $this- _queue- consume($fun_name); 
}

定单付款取得成功,载入序列编码

 ?php 
set_time_limit(0); 
include_once('RabbitMQCommand.php'); 
$configs = array('host'= '127.0.0.1','port'= 5672,'username'= 'asdf','password'= '123456','vhost'= '/'); 
$exchange_name = 'class-e-1'; 
$queue_name = 'class-q-1'; 
$route_key = 'class-r-1'; 
$ra = new RabbitMQCommand($configs,$exchange_name,$queue_name,$route_key); 
for($i=0;$i =100;$i++){ 
 $ra- send(date('Y-m-d H:i:s',time())); 
exit();

解决定单序列脚本制作编码

 ?php 
error_reporting(0); 
include_once('RabbitMQCommand.php'); 

$configs = array('host'= '127.0.0.1','port'= 5672,'username'= 'asdf','password'= '123456','vhost'= '/'); $exchange_name = 'class-e-1'; $queue_name = 'class-q-1'; $route_key = 'class-r-1'; $ra = new RabbitMQCommand($configs,$exchange_name,$queue_name,$route_key);
$pid = posix_getpid(); file_put_contents("log{$pid}.log", $msg.'|'.$envelopeID.''."\r\n",FILE_APPEND); $queue- ack($envelopeID); $a = new A();
$s = $ra- run(array($a,'processMessage'),false);

PS.我这儿用的是rabbitma序列来解决,全部php运作必须amq的拓展

 



新闻资讯

联系方式丨CONTACT

  • 全国热线:18720358503
  • 传真热线:18720358503
  • Q Q咨询:2639601583
  • 企业邮箱:2639601583@qq.com

首页
电话
短信
联系