ups https://www.e-learn.cn/tag/ups zh-hans 功率因素 https://www.e-learn.cn/topic/3536220 <span>功率因素</span> <span><span lang="" about="/user/57" typeof="schema:Person" property="schema:name" datatype="">瘦欲@</span></span> <span>2020-03-29 05:17:29</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"> <p>长期以来,不论是UPS的供应商还是用户,在UPS功率因数问题上,一直都在讨论着一个焦点性的问题:用户声言要高功率因数的UPS,供应商也说这个数值越大越好,于是各厂家就尽全力去提高这个参数。到底UPS的功率因数是大点好还是小点好呢?  <br />     功率因数是指任意二端网络(与外界有二个接点的电路)两端电压U与其中电流I之间的位相差的余弦 。在二端网络中消耗的功率是指平均功率,也称为有功功率,它等于</p><p></p><img class="b-lazy" data-src="https://www.eimg.top/images/2020/04/03/4e651032ac0b4d6a57662d2df2f39447.gif" data-original="https://www.eimg.top/images/2020/04/03/4e651032ac0b4d6a57662d2df2f39447.gif" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /><p></p> <br />由此可以看出,电路中消耗的功率P,不仅取决于电压V与电流I的大小,还与功率因数有关。而功率因数的大小,取决于电路中负载的性质。对于电阻性负载,其电压与电流的位相差为0,因此,电路的功率因数最大(<p></p><img class="b-lazy" data-src="https://www.eimg.top/images/2020/04/03/71c88f1d69eb161bdaa59b53c2ddff23.gif" data-original="https://www.eimg.top/images/2020/04/03/71c88f1d69eb161bdaa59b53c2ddff23.gif" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /><p></p>);而纯电感电路,电压与电流的位相差为π/2,并且是电压超前电流;在纯电容电路中,电压与电流的位相差则为-(π/2),即电流超前电压。在后两种电路中,功率因数都为0。对于一般性负载的电路,功率因数就介于0与1之间。 <p> 一般来说,在二端网络中,提高用电器的功率因数有两方面的意义,一是可以减小输电线路上的功率损失;二是可以充分发挥电力设备(如发电机、变压器等)的潜力。因为用电器总是在一定电压U和一定有功功率P的条件下工作,由<b>公式</b>: <br /></p><p></p><img class="b-lazy" data-src="https://www.eimg.top/images/2020/04/03/ac8820a991110ef101248ea19e38dd4e.gif" data-original="https://www.eimg.top/images/2020/04/03/ac8820a991110ef101248ea19e38dd4e.gif" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /><p></p> <br />可知,功率因数过低,就要用较大的电流来保障用电器正常工作,与此同时输电线路上输电电流增大,从而导致线路上焦耳热损耗增大。另外,在输电线路的电阻上及电源的内组上的电压降,都与用电器中的电流成正比,增大电流必然增大在输电线路和电源内部的电压损失。因此,提高用电器的功率因数,可以减小输电电流,进而减小了输电线路上的功率损失。 <p> UPS有两个功率因数值:输入功率因数和输出功率因数。输入功率因数表示UPS对电网有功功率的吸收能力及对电网的影响程度;输出功率因数表示UPS对非线性负载的适应能力。当然,对输入功率因数的要求显然是越高越好,而UPS得输出功率因数却并不一定越高越好。  <br /> 下面先来看看几个概念:  <br /> 视在功率(S):即交流电压和交流电流的乘积。其单位为伏安,UPS的标称容量就是指其视在功率,即额定输出电压和额定输出电流的乘积。用公式表示为: S=U×I  <br /> 视在功率包括两部分:输出有功功率(P)和无功功率(Q)。  <br /> 有功功率(P):指直接做功的部分,单位为瓦(W)。比如使灯发亮,使电机运转等。因为这个功率做功后都变成了热量,转化成热能、光能、机械能等,可以被人明显地感知到。有功功率只是视在功率的一部分,它与视在功率的关系为:P=S×cosφ=U×I×cosφ 。  <br /> 其中cosφ即为功率因数,角φ是在非线性负载时,电压电流的相位差。功率因数表征着UPS输出有功功率的能力。  <br /> 无功功率(Q):是指储存在电路中但不直接做功的那部分功率,单位为乏(var)。其数值用公式表示为:Q=S×sinφ=U×I×sinφ  <br /> 虽然无功功率不转化为其他的能量形式,但对于计算机等非线性负载来说,没有无功功率却根本无法工作。  <br /> 大多数人都认为既然无功功率不做功,当然可以不要。于是认为功率因数为1的电源最好,可以输出最大的功率。然而实际情况并非如此。  <br /> 首先从负载方面来说。  <br /> 比如说计算机吧,当市电输入后,要进行整流处理,如果去掉输出端的电容C,将整流桥的输出电压直接输出给计算机,则这时计算机的功率因数接近于1,但输出的直流电压是忽大忽小,上下起伏的脉动波,显然这样的电压是无法让计算机正常工作的,这么高的功率因数又有什么用呢?为了让计算机能正常工作,在整流桥输出端加个大电容,来进行滤波,以向计算机输入平滑的直流电压Uo,这个电容滤波器就像一个水库一样,里面必须储存足够数量的电荷,在整流桥输出电压偏低时,补充电荷;偏高时储存电荷,保证Uo的电压不会有显著的脉动变化,以输出平滑的直流电压。储存在电容器里的这部分能量其实就是无功功率。有的平滑滤波电路用电感或电容与电感共同组成,但无论哪种,原理都是相通的,可电路中,只要存在电容或电感,功率因数就不会再为1了。因此说,计算机之类的非线性负载不仅需要有功功率,同样也需要无功功率才能正常工作。  <br /> 再从电源设备-UPS来说。  <br /> UPS绝大多数都是用于计算机或类似计算机之类的非线性负载,很少有用来照明或带电热器之类的线性负载。这类非线性设备一般都是直接输入市电后进行整流、滤波。这些设备对市电构成了非线性负载,功率因数基本上在0.6~0.7。从电路的基本原理来说,当负载阻抗于电源阻抗相等时,电源的利用率最高,工作在最佳状态,此时电源与负载才叫匹配。为了使UPS和这些设备匹配,最好也应具有相近甚至相等的功率因数值。如世界上知名的UPS品牌,意大利的BORRI,美国的艾克赛、法国的梅兰日兰,瑞士的固特,德国的西门子等都具有这样的输出功率因数。  <br />      现在假设UPS的输出功率因数为1,则此时无功功率为0,对计算机这样的非线性负载而言,显然无法应用,这样的电源也就只能纯带线性负载了,此时如果电流稍有变化,输出电压就要几十伏地增加,而且过载能力极差,这种情况下,电源根本就无法工作。在现实生活中,UPS用于纯线性负载的场合也极少的。  <br /> 其实,UPS的逆变器的输出特性与负载的功率因数有个对应关系,在功率因数为1时,UPS只能输出80%的额定容量,随着功率因数的降低,UPS的输出能量也相应的变大,当功率因数为0.8时,恰好可以输出100%的额定容量。即负载功率因数越小,输出的VA功率值越大,换句话说,对付非线性负载的能力越强,而计算机恰恰就是典型的非线性负载,如果让UPS的输出功率因数计算机系统的越相近,则越可能构成最佳配合,此时,有功功率用满了,无功功率也刚好用满,充分发挥了设备的潜力。  <br /> 一般说,UPS的输入功率因数的提高对输入电网有利,可以减小对电网的干扰。因此这个参数越大越好,但对UPS本身来说,好处并不是很明显。为了降低对电网造成的公害,UPS的输入功率因数也是尽量做大,但这样做势必增加控制电路的复杂程度,增加元器件,增加成本,所以,这也是传统的UPS一般不急于提高输入功率因数的原因之一。  <br />   UPS的输出功率因数真正含义是适应负载的能力,即能适应多大功率的负载,而不单是提供有功功率的百分比。比如,在一定范围内,如果是线性负载,UPS的输出功率因数就是1;如果是计算机之类的非线性负载,UPS的输出功率因数也应该与其相匹配,为0.6~0.7。也就是说,UPS的输出功率因数是随负载而变化的。  <br /> 总之,无论是UPS的输入功率因数还是输出功率因数,都是可以通过一定的手段提高的,问题是有无这个必要的问题。UPS的输出功率因数并不是越大越好,可以这样说:小功率因数的UPS包含有大功率因数的特点,大功率因数的UPS却代替不了小功率因数UPS的功能。UPS的输出功率因数大小完全是随负载的性质而变,并不是UPS要给负载输出什么性质的功率,而是负载需要什么性质的功率,UPS应该适应负载,而不是负载去适应UPS。  </p> <div class="alert alert-success" role="alert"><p>来源:<code>https://www.cnblogs.com/ziqiang/archive/2011/05/17/2049421.html</code></p></div></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/gongluyinshu" hreflang="zh-hans">功率因数</a></div> <div class="field--item"><a href="/tag/ups" hreflang="zh-hans">ups</a></div> <div class="field--item"><a href="/tag/gonglu" hreflang="zh-hans">功率</a></div> <div class="field--item"><a href="/tag/xianxingxitong" hreflang="zh-hans">线性系统</a></div> <div class="field--item"><a href="/tag/feixianxing" hreflang="zh-hans">非线性</a></div> <div class="field--item"><a href="/tag/shuchugonglu" hreflang="zh-hans">输出功率</a></div> </div> </div> Sat, 28 Mar 2020 21:17:29 +0000 瘦欲@ 3536220 at https://www.e-learn.cn MySQL-安装mysql8 https://www.e-learn.cn/topic/3535390 <span>MySQL-安装mysql8</span> <span><span lang="" about="/user/104" typeof="schema:Person" property="schema:name" datatype="">元气小坏坏</span></span> <span>2020-03-28 12:34:51</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"> <h2>1. 安装配置</h2><pre># 解压 tar -xf mysql-8.0.18-el7-x86_64.tar.gz -C /ups/app/mysql/ cd /ups/app/mysql/ mv mysql-8.0.18-el7-x86_64 mysql8 cd mysql8 mkdir -p {config,logs} mkdir -p /ups/data/mydata/mysql8 chown -R mysql:mysql . chown -R mysql:mysql /ups/data/mydata/mysql8 chmod 700 /ups/data/mydata/mysql8 cat&gt; config/my.cnf &lt;&lt;-EOF [mysqld] basedir = /ups/app/mysql/mysql8 datadir = /ups/data/mydata/mysql8 log-error = /ups/app/mysql/mysql8/logs/mysql6033.err pid-file = /ups/app/mysql/mysql8/logs/mysql6033.pid socket = /ups/app/mysql/mysql8/logs/mysql6033.sock port = 6033 default-storage-engine = INNODB character-set-server = utf8mb4 collation-server = utf8mb4_general_ci # connect limits max_connect_errors = 5 max_connections = 1000 max_user_connections = 100 wait_timeout = 100 open_files_limit = 1024 # 限制将系统文件读到数据库(/etc/passwd) local-infile = 0 skip_name_resolve = ON server_id = 6033001 # error log、genera log timestamp log_timestamps=SYSTEM # 在关闭是将热数据dump到本地磁盘 innodb_buffer_pool_dump_at_shutdown = 1 # 在启动时将热数据加载到内存 innodb_buffer_pool_load_at_startup = 1 EOF # 初始化MySQL /ups/app/mysql/mysql8/bin/mysqld --defaults-file=/ups/app/mysql/mysql8/config/my.cnf --user=mysql --basedir=/ups/app/mysql/mysql8 --datadir=/ups/data/mydata/mysql8 --initialize # 启动服务 /ups/app/mysql/mysql8/bin/mysqld_safe --defaults-file=/ups/app/mysql/mysql8/config/my.cnf &amp; </pre><h2>2. 配置账号</h2><pre># mysql8 默认使用caching_sha2_password算法 # 修改root账号密码 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'; # 远程登录 create user root@'192.168.10.%' IDENTIFIED WITH mysql_native_password BY 'root' ; grant all privileges on *.* to 'root'@'192.168.10.%' with grant option; flush privileges; # 检查确认 select host,user, authentication_string, plugin from mysql.user; </pre> <div class="alert alert-success" role="alert"><p>来源:<code>https://www.cnblogs.com/binliubiao/p/12586651.html</code></p></div></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/mysql" hreflang="zh-hans">mysql</a></div> <div class="field--item"><a href="/tag/ups" hreflang="zh-hans">ups</a></div> <div class="field--item"><a href="/tag/root" hreflang="zh-hans">root</a></div> <div class="field--item"><a href="/tag/mysqlshujuku" hreflang="zh-hans">mysql数据库</a></div> </div> </div> Sat, 28 Mar 2020 04:34:51 +0000 元气小坏坏 3535390 at https://www.e-learn.cn Woocommerce - Create Free shipping for single item while using UPS extension https://www.e-learn.cn/topic/3302731 <span>Woocommerce - Create Free shipping for single item while using UPS extension</span> <span><span lang="" about="/user/236" typeof="schema:Person" property="schema:name" datatype="">南楼画角</span></span> <span>2020-01-25 00:43:28</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I am using the UPS extension in woocommerce. I need to offer free shipping on some items, bypassing the UPS calculator. It seems one good way to do this is to mark the item as "virtuaL," but then the item doesn't require shipping. I need to require shipping for this item. I have been able to customize the checkout page and force the shipping fields to show on the virtual items, but then they don't store in the actual orders.</p> <p>Anybody know how I can create a custom function or modify the woocommerce files to force the checkout process to require shipping on a virtual item, all while bypassing the UPS calculator? (other items need to be calculated for shipping)</p> <br /><h3>回答1:</h3><br /><p>I was having the same issue, the Author of the plugin replied to me that it can't be done, one have to write the code to do that.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>I just ran into this issue, maybe this will help someone out. For all of the products that I wanted free shipping, I made virtual products.</p> <p>Then I went to Woocommerce &gt; Shipping Options Tab, check the box that says "Collect shipping address even when not required" which is in the "Shipping Destination section".</p> <br /><br /><br /><h3>回答3:</h3><br /><p>I needed exactly this as well, and have a workable solution:</p> <p>First go into your <code>functions.php</code> in <code>"Appearance"-&gt;"Editor"-&gt;"Theme Functions"</code>, and add the following code (I highly recommend using a "child theme" first, so you are not modifying your theme's <code>functions.php</code>...or you could alternatively create a custom plugin).</p> <pre><code>/* Puts items with "free-shipping" shipping class into a different shipping package. */ function free_woocommerce_cart_shipping_packages( $packages ) { // Reset the packages $packages = array(); // Free items $freeshipping_items = array(); $regular_items = array(); // Sort free from regular (replace "free-shipping" below with the shipping class slug you actually use). foreach( WC()-&gt;cart-&gt;get_cart() as $item ) { if( $item['data']-&gt;needs_shipping() ) { if( $item['data']-&gt;get_shipping_class() == 'free-shipping' ) { $freeshipping_items[] = $item; } else { $regular_items[] = $item; } } } // Put inside packages: if( $freeshipping_items ) { $packages[] = array( 'ship_via' =&gt; array( 'flat_rate' ), 'contents' =&gt; $freeshipping_items, 'contents_cost' =&gt; array_sum(wp_list_pluck($freeshipping_items, 'line_total')), 'applied_coupons' =&gt; WC()-&gt;cart-&gt;applied_coupons, 'destination' =&gt; array( 'country' =&gt; WC()-&gt;customer-&gt;get_shipping_country(), 'state' =&gt; WC()-&gt;customer-&gt;get_shipping_state(), 'postcode' =&gt; WC()-&gt;customer-&gt;get_shipping_postcode(), 'city' =&gt; WC()-&gt;customer-&gt;get_shipping_city(), 'address' =&gt; WC()-&gt;customer-&gt;get_shipping_address(), 'address_2' =&gt; WC()-&gt;customer-&gt;get_shipping_address_2() ) ); } if( $regular_items ) { $packages[] = array( // 'ship_via' =&gt; array( 'usps' ), 'contents' =&gt; $regular_items, 'contents_cost' =&gt; array_sum(wp_list_pluck($regular_items, 'line_total')), 'applied_coupons' =&gt; WC()-&gt;cart-&gt;applied_coupons, 'destination' =&gt; array( 'country' =&gt; WC()-&gt;customer-&gt;get_shipping_country(), 'state' =&gt; WC()-&gt;customer-&gt;get_shipping_state(), 'postcode' =&gt; WC()-&gt;customer-&gt;get_shipping_postcode(), 'city' =&gt; WC()-&gt;customer-&gt;get_shipping_city(), 'address' =&gt; WC()-&gt;customer-&gt;get_shipping_address(), 'address_2' =&gt; WC()-&gt;customer-&gt;get_shipping_address_2() ) ); } return $packages; } add_filter('woocommerce_cart_shipping_packages', 'free_woocommerce_cart_shipping_packages'); </code></pre> <p>Second, go into the <code>"Products"-&gt;"Shipping Classes"</code> and create a Shipping Class called "<code>Free Shipping</code>" with a slug called "<code>free-shipping</code>" (the slug name is what we will tie our custom function to). Then "<code>Add New Shipping Class</code>".</p> <p>Then in your <code>"WooCommerce"-&gt;"Settings"-&gt;"Shipping"-&gt;"Flat Rate"</code> enable "<code>Flat Rate</code>" shipping, and under the "<code>Shipping Class Costs</code>" section put a value of "<code>0.00</code>" next to the "<code>Free Shipping</code>" class we just created. In my case, I also have "<code>Calculation Type</code>" set to "<code>Per Class</code>". Then "<code>Save changes</code>".</p> <p>Then finally in <code>"WooCommerce"-&gt;"Settings"-&gt;"Shipping"-&gt;"Shipping Options"</code> in the "<code>Shipping Methods</code>" section, make sure "<code>Flat Rate</code>" has a higher "<code>Selection Priority</code>" (in the column of that name) than whatever other shipping method(s) you are using, and that it is the last one on the list (you can drag to reorder using the menu icon on the left of each option). "<code>Save Changes</code>".</p> <p>Then edit one of your products that you wish to have free shipping, go to the "<code>Product Data"-&gt;"Shipping</code>" section and change the shipping class to "<code>Free Shipping</code>" (the new class you created). Then "<code>Update</code>" that product to save the changes. Then also add it to your cart, and also add some other item to your cart that has regular non-free shipping.</p> <p><strong>Test.</strong></p> <p>You should now see that free shipping items get their own shipping "package" row ("<code>Shipping #1</code>" and "<code>Shipping #2</code>") separate from the items that should still charge for shipping, even when you have some of each kind in the shopping cart.</p> <p>Alternatively, you could also try the full paid plugin called "Per Product Shipping".</p> <p>Or this free plugin may work as well (no promises).</p> <br /><br /><br /><h3>回答4:</h3><br /><p>Another way that I believe may help you to make an item have "free" shipping (and a way I have used in the past), is to create a <strong>coupon</strong> that will discount the product (don't mark it as "virtual") to that of it's price minus shipping. </p> <p>So say for example your product is $100 and shipping is $10 (total of $110), you then create a coupon specifically for that for product(s) that will give it a $10 discount making your product &amp; shipping total $100. </p> <p>I assume you already know how to create coupons in woocommerce (if you need some refreshing on how to do so this page will help). To make the coupons <strong>apply to a specific products</strong> which you want to have free shipping, go to Usage Restriction-&gt;Products and specify the specific product you want to have "free" (or in this case, discounted) shipping.</p> <p>To save the user the trouble of entering this coupon code upon checkout, you can add the following code to functions.php:</p> <pre><code>//Check for specific products then discount to adjust for 'free' shipping. function my_free_shipping(){ //variables. global $woocommerce; $coupon_code = 'free-shiping'; $products= array('1', '2'); //products (ID's) to have discounted shipping. //get the cart contents. $cart_item = $woocommerce-&gt;cart-&gt;get_cart(); //loop through the cart items looking for the products in $products. foreach ($cart_item as $key =&gt; $item){ //check if the cart items match to any of those in the array. if(in_array($item['product_id'], $products)){ //apply discount. $woocommerce-&gt;cart-&gt;add_discount(sanitize_text_field($coupon_code)); } } } add_action('init', 'my_free_shipping'); </code></pre> <p>Please note that I have <strong>not tested</strong> this code with the UPS extension yet, but feel free to modify and play around with it. </p> <p>I hope this post is/was of some help to you!</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/15457059/woocommerce-create-free-shipping-for-single-item-while-using-ups-extension</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/woocommerce" hreflang="zh-hans">woocommerce</a></div> <div class="field--item"><a href="/tag/shipping" hreflang="zh-hans">shipping</a></div> <div class="field--item"><a href="/tag/ups" hreflang="zh-hans">ups</a></div> </div> </div> Fri, 24 Jan 2020 16:43:28 +0000 南楼画角 3302731 at https://www.e-learn.cn UPS(不间断电源)简介 https://www.e-learn.cn/topic/3276459 <span>UPS(不间断电源)简介</span> <span><span lang="" about="/user/108" typeof="schema:Person" property="schema:name" datatype="">青春壹個敷衍的年華</span></span> <span>2020-01-22 04:12:18</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><div class="htmledit_views" id="content_views"> <p>本文简单介绍UPS(不间断电源)的相关知识。</p> <h1>1 概述</h1> <p>UPS(Uninterrupted Power Supply),即不间断电源,是将蓄电池与主机相连接,通过主机逆变器等模块电路,将蓄电池中直流(DC,Direct Current)电转换成市电交流(AC,Alternating Current)电的系统设备。UPS 主要用于给单台计算机、计算机网络系统或其它电力电子设备如电磁阀、压力变送器等提供稳定、不间断的电力供应。<br /> 当市电输入正常时,UPS 将市电稳压后供应给负载使用,此时的UPS就是一台交流式电稳压器,同时它还向机内蓄电池充电;当市电中断(事故停电)时, UPS 立即将蓄电池的直流电能,通过逆变器切换转换的方法,向负载继续供应220V交流电,使负载维持正常工作,并保护负载的软、硬件不受损坏。此外,UPS 设备通常对电压过高或电压过低都能提供保护。</p> <h1>2 工作原理</h1> <p>UPS 的工作原理如下图:</p> <p><img alt="" class="has b-lazy" height="152" width="481" data-src="https://img-blog.csdnimg.cn/20200121095816728.png" data-original="https://img-blog.csdnimg.cn/20200121095816728.png" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /></p> <p>从上图中可以看到,在电网电压工作正常时,UPS 给负载供电,同时给蓄电池充电;当突发停电时,UPS 电源开始工作,由蓄电池为负载提供所需电源(黑色箭头所示);此外,当由于生产需要,负载严重过载时,由电网电压经整流直接给负载供电(如虚线所示)。</p> <h1>3 总结</h1> <p>综上所述,能够得知 UPS 的主要作用是在市电中断时为负载继续提供市电,即事故停电时的电力保障,所以,<strong>将 UPS 作为“大容量备用电池”使用并不合适,也就是说,对于需要备用电池的应用场景,应该选择真正的备用电池,而非 UPS</strong>。</p> <p> </p> </div><div class="alert alert-success" role="alert"><p>来源:<code>CSDN</code></p><p>作者:<code>liitdar</code></p><p>链接:<code>https://blog.csdn.net/liitdar/article/details/104058642</code></p></div></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/bujianduandianyuan" hreflang="zh-hans">不间断电源</a></div> <div class="field--item"><a href="/tag/ups" hreflang="zh-hans">ups</a></div> <div class="field--item"><a href="/tag/xudianchi" hreflang="zh-hans">蓄电池</a></div> <div class="field--item"><a href="/tag/shuma" hreflang="zh-hans">数码</a></div> <div class="field--item"><a href="/tag/upsdianchi" hreflang="zh-hans">ups电池</a></div> </div> </div> Tue, 21 Jan 2020 20:12:18 +0000 青春壹個敷衍的年華 3276459 at https://www.e-learn.cn How to prevent data loss in a .net application due to sudden power failure? https://www.e-learn.cn/topic/3138429 <span>How to prevent data loss in a .net application due to sudden power failure?</span> <span><span lang="" about="/user/44" typeof="schema:Person" property="schema:name" datatype="">a 夏天</span></span> <span>2020-01-06 20:18:36</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>We are developing an RetailPOS .net (windows) application. </p> <p>One of the customer asks 'What will happen to current data being processed in the application when a power went off suddenly?', 'Will the application able to recover the unsaved data?'</p> <p>I am wondering, how this feature can be included in the .net application? </p> <p>Can some help me, what needs to be done for this?</p> <br /><h3>回答1:</h3><br /><p>First, look into a UPS (un-interuptable power supply)</p> <p>Second, look into creating persistent transactions, transactions that will save early and often, but not commit until you tell it to. This goes a little beyond the typical transactions in TSQL.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>If it's a hard power-cut (like the battery removed on a laptop while unplugged), then there's not much you can do other than write to disk every. step. of. the. way. (Talk about a performance hit.) And also make sure that you have something recorded to let the application know when it starts back up what it was in the middle of doing before, so it can either continue, or retry the operation.</p> <p>If it's a power-cut, like the power button being pressed to shutdown/sleep/hibernate the computer, then listen for the SystemEvents.PowerModeChanged event and act accordingly. </p> <p>Lastly, make sure that if your data would be corrupted if halfway written to a database, make sure your database writes are atomic (either all the changes happen and are accepted, or none of them are).</p> <br /><br /><br /><h3>回答3:</h3><br /><p>You can append the current information being received to the file system. It will be a performance hit, but will allow you to get back to the last item being captured. </p> <p>When the application starts detect if there is a pending file, and provide the option to recover. Load the data saved in the file appropriately.</p> <p>Once you have all the information, when you are doing the process that happens when paying, make sure to record any significant changes in the process atomically. If you are hitting external systems, record when you are initiating the operation and when it comes back right away. In the above there is always a window of time when it can fail, but you want to keep it as short as possible and to have enough information for the recovery processes. Worst case if the system can't automatically recover, you want it to have enough information to determine where in the process it stopped.</p> <br /><br /><br /><h3>回答4:</h3><br /><p>What you really want are atomic on disk transactions. There are many ways to perform these, but often times if you are using an existing database product it will be done for you.</p> <p>If you rolled your own database or file formats, you have some work cut our for you depending on your file format. </p> <br /><br /><br /><h3>回答5:</h3><br /><p>PowerFailureException class will solve this. Actually just maintain power with a UPS. The only other option really is to maintain atomicity for database transactions.</p> <br /><br /><br /><h3>回答6:</h3><br /><p>You might want to consider having your application use SQLite.</p> <p>They have some great info on their when to use page.</p> <p>Some points that stand out are:</p> <blockquote> <ul><li><p>Updates happen atomically as application content is revised</p></li> <li><p>Content is updated continuously and atomically so that there is no work lost in the event of a power failure or crash.</p></li> </ul></blockquote> <p>I'm looking for a similar option for an application I am going to implement which will be used in a third world country where the power goes out frequently throughout the day....so far SQLite seems to stand out as a good possible choice.</p> <p>But at the end of the day, your choice will depend on your individual circumstances and requirements.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/736712/how-to-prevent-data-loss-in-a-net-application-due-to-sudden-power-failure</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/net" hreflang="zh-hans">.net</a></div> <div class="field--item"><a href="/tag/winforms" hreflang="zh-hans">winforms</a></div> <div class="field--item"><a href="/tag/ups" hreflang="zh-hans">ups</a></div> </div> </div> Mon, 06 Jan 2020 12:18:36 +0000 a 夏天 3138429 at https://www.e-learn.cn How to prevent data loss in a .net application due to sudden power failure? https://www.e-learn.cn/topic/3138383 <span>How to prevent data loss in a .net application due to sudden power failure?</span> <span><span lang="" about="/user/15" typeof="schema:Person" property="schema:name" datatype="">假装没事ソ</span></span> <span>2020-01-06 20:17:12</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>We are developing an RetailPOS .net (windows) application. </p> <p>One of the customer asks 'What will happen to current data being processed in the application when a power went off suddenly?', 'Will the application able to recover the unsaved data?'</p> <p>I am wondering, how this feature can be included in the .net application? </p> <p>Can some help me, what needs to be done for this?</p> <br /><h3>回答1:</h3><br /><p>First, look into a UPS (un-interuptable power supply)</p> <p>Second, look into creating persistent transactions, transactions that will save early and often, but not commit until you tell it to. This goes a little beyond the typical transactions in TSQL.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>If it's a hard power-cut (like the battery removed on a laptop while unplugged), then there's not much you can do other than write to disk every. step. of. the. way. (Talk about a performance hit.) And also make sure that you have something recorded to let the application know when it starts back up what it was in the middle of doing before, so it can either continue, or retry the operation.</p> <p>If it's a power-cut, like the power button being pressed to shutdown/sleep/hibernate the computer, then listen for the SystemEvents.PowerModeChanged event and act accordingly. </p> <p>Lastly, make sure that if your data would be corrupted if halfway written to a database, make sure your database writes are atomic (either all the changes happen and are accepted, or none of them are).</p> <br /><br /><br /><h3>回答3:</h3><br /><p>You can append the current information being received to the file system. It will be a performance hit, but will allow you to get back to the last item being captured. </p> <p>When the application starts detect if there is a pending file, and provide the option to recover. Load the data saved in the file appropriately.</p> <p>Once you have all the information, when you are doing the process that happens when paying, make sure to record any significant changes in the process atomically. If you are hitting external systems, record when you are initiating the operation and when it comes back right away. In the above there is always a window of time when it can fail, but you want to keep it as short as possible and to have enough information for the recovery processes. Worst case if the system can't automatically recover, you want it to have enough information to determine where in the process it stopped.</p> <br /><br /><br /><h3>回答4:</h3><br /><p>What you really want are atomic on disk transactions. There are many ways to perform these, but often times if you are using an existing database product it will be done for you.</p> <p>If you rolled your own database or file formats, you have some work cut our for you depending on your file format. </p> <br /><br /><br /><h3>回答5:</h3><br /><p>PowerFailureException class will solve this. Actually just maintain power with a UPS. The only other option really is to maintain atomicity for database transactions.</p> <br /><br /><br /><h3>回答6:</h3><br /><p>You might want to consider having your application use SQLite.</p> <p>They have some great info on their when to use page.</p> <p>Some points that stand out are:</p> <blockquote> <ul><li><p>Updates happen atomically as application content is revised</p></li> <li><p>Content is updated continuously and atomically so that there is no work lost in the event of a power failure or crash.</p></li> </ul></blockquote> <p>I'm looking for a similar option for an application I am going to implement which will be used in a third world country where the power goes out frequently throughout the day....so far SQLite seems to stand out as a good possible choice.</p> <p>But at the end of the day, your choice will depend on your individual circumstances and requirements.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/736712/how-to-prevent-data-loss-in-a-net-application-due-to-sudden-power-failure</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/net" hreflang="zh-hans">.net</a></div> <div class="field--item"><a href="/tag/winforms" hreflang="zh-hans">winforms</a></div> <div class="field--item"><a href="/tag/ups" hreflang="zh-hans">ups</a></div> </div> </div> Mon, 06 Jan 2020 12:17:12 +0000 假装没事ソ 3138383 at https://www.e-learn.cn Regular Expression patterns for Tracking numbers https://www.e-learn.cn/topic/2981255 <span>Regular Expression patterns for Tracking numbers</span> <span><span lang="" about="/user/159" typeof="schema:Person" property="schema:name" datatype="">余生颓废</span></span> <span>2019-12-29 02:32:49</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>Does anybody know good place or patterns for checking which company tracking number is the given tracking number for a package. Idea is After scanning a barcode for a package check tracking number with patterns and show which company it was shipped by. </p> <br /><h3>回答1:</h3><br /><p>Just thought I would post an update on this as I am working on this to match via jquery and automatically select the appropriate shipping carrier. I compiled a list of the matching regex for my project and I have tested a lot of tracking numbers across UPS FedEX and USPS. </p> <p>If you come across something which doesn't match, please let me know here via comments and I will try to come up for that as well.</p> <p>UPS:</p> <pre><code>/\b(1Z ?[0-9A-Z]{3} ?[0-9A-Z]{3} ?[0-9A-Z]{2} ?[0-9A-Z]{4} ?[0-9A-Z]{3} ?[0-9A-Z]|[\dT]\d\d\d ?\d\d\d\d ?\d\d\d)\b/ </code></pre> <p>FedEX: (3 Different Ones)</p> <pre><code>/(\b96\d{20}\b)|(\b\d{15}\b)|(\b\d{12}\b)/ /\b((98\d\d\d\d\d?\d\d\d\d|98\d\d) ?\d\d\d\d ?\d\d\d\d( ?\d\d\d)?)\b/ /^[0-9]{15}$/ </code></pre> <p>USPS: (4 Different Ones)</p> <pre><code>/(\b\d{30}\b)|(\b91\d+\b)|(\b\d{20}\b)/ /^E\D{1}\d{9}\D{2}$|^9\d{15,21}$/ /^91[0-9]+$/ /^[A-Za-z]{2}[0-9]+US$/ </code></pre> <p>Please note that I did not come up with these myself. I simply searched around and compiled the list from different sources, including some which may have been mentioned here.</p> <p>Thanks</p> <p>Edit: Fixed missing end delimiter.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>I pressed Royal Mail for a regex for the Recorded Delivery &amp; Special Delivery tracking references but didn't get very far. Even a full set of rules so I could roll my own was beyond them.</p> <p>Basically, even after they had taken about a week and came back with various combinations of letters denoting service type, I was able to provide examples from our experience that showed there were additional combinations that were obviously valid but that they had not documented.</p> <p>The references follow the apparently standard international format that I think Jefe's <code>/^[A-Za-z]{2}[0-9]+GB$/</code> regex would describe:</p> <blockquote> <p>XX123456789GB </p> </blockquote> <p>Even though this seems to be a standard format, i.e. most international mail has the same format where the last two letters denote the country of origin, I've not been able to find out any more about this 'standard' or where it originates from (any clarification welcome!).</p> <p>Particular to Royal Mail seems to be the use of the first two letters to denote service level. I have managed to compile a list of prefixes that denote Special Delivery, but am not convinced that it is 100% complete:</p> <pre><code>AD AE AF AJ AK AR AZ BP CX DS EP HC HP KC KG KH KI KJ KQ KU KV KW KY KZ PW SA SC SG SH SI SJ SL SP SQ SU SW SY SZ TX WA WH XQ WZ </code></pre> <p>Without one of these prefixes the service is Recorded Delivery which gives delivery confirmation but no tracking.</p> <p>It seems generally that inclusion of an S, X or Z denotes a higher service level and I don't think I've ever seen a normal Recorded Delivery item with any of those letters in the prefix.</p> <p>However, as you can see there are many prefixes that would need to be tested if service level were to be checked using regex, and given the fact that Royal Mail seem incapable of providing a comprehensive rule set then trying to test for service level may be futile.</p> <br /><br /><br /><h3>回答3:</h3><br /><p>I need to verify JUST United States Postal Service (USPS) tracking numbers. WikiAnswers says that my number formats are as follows:</p> <blockquote> <p>USPS only offers tracking with Express mail, with usually begins with an "E", another letter, followed by 9 digits, and two more letters. USPS does have "Label numbers" for other services that are between 16 and 22 digits long.</p> <p>http://wiki.answers.com/Q/How_many_numbers_in_a_USPS_tracking_number</p> </blockquote> <p>I'm adding in that the Label numbers start with a "9" as all the ones I have from personal shipments for the past 2 years start with a 9.</p> <p>So, assuming that WikiAnswers is correct, here is my regex that matches both:</p> <pre><code>/^E\D{1}\d{9}\D{2}$|^9\d{15,21}$/ </code></pre> <p>It's pretty simple. Here is the break down:</p> <pre><code>^E - Begins w/ E (For express number) \D{1} - followed by another letter \d{9} - followed by 9 numbers \D{2} - followed by 2 more letters $ - End of string | - OR ^9 - Basic Track &amp; Ship Number \d{15,21} - followed by 15 to 21 numbers $ - End of string </code></pre> <p>Using www.gummydev.com's regex tester this patter matches both of my test strings:</p> <p>EXPRESS MAIL : EK225651436US</p> <p>LABEL NUMBER: 9410803699300003725216</p> <p>**Note: If you're using ColdFusion (I am), remove the first and last "/" from the pattern</p> <br /><br /><br /><h3>回答4:</h3><br /><p>Here are some sample numbers from the main US carriers:</p> <pre><code>USPS: 70160910000108310009 (certified) 23153630000057728970 (signature confirmation) RE360192014US (registered mail) EL595811950US (priority express) 9374889692090270407075 (regular) FEDEX: 810132562702 (all seem to follow same pattern regardless) 795223646324 785037759224 UPS: K2479825491 (UPS ground) J4603636537 (UPS next day express) 1Z87585E4391018698 (regular) </code></pre> <p>Patterns I am using (php code). Yep I gave up and started testing against all the patterns at my disposal. Had to write the second UPS one. </p> <pre><code>public function getCarrier($trackingNumber){ $matchUPS1 = '/\b(1Z ?[0-9A-Z]{3} ?[0-9A-Z]{3} ?[0-9A-Z]{2} ?[0-9A-Z]{4} ?[0-9A-Z]{3} ?[0-9A-Z]|[\dT]\d\d\d ?\d\d\d\d ?\d\d\d)\b/'; $matchUPS2 = '/^[kKJj]{1}[0-9]{10}$/'; $matchUSPS0 = '/(\b\d{30}\b)|(\b91\d+\b)|(\b\d{20}\b)/'; $matchUSPS1 = '/(\b\d{30}\b)|(\b91\d+\b)|(\b\d{20}\b)|(\b\d{26}\b)| ^E\D{1}\d{9}\D{2}$|^9\d{15,21}$| ^91[0-9]+$| ^[A-Za-z]{2}[0-9]+US$/i'; $matchUSPS2 = '/^E\D{1}\d{9}\D{2}$|^9\d{15,21}$/'; $matchUSPS3 = '/^91[0-9]+$/'; $matchUSPS4 = '/^[A-Za-z]{2}[0-9]+US$/'; $matchUSPS5 = '/(\b\d{30}\b)|(\b91\d+\b)|(\b\d{20}\b)|(\b\d{26}\b)| ^E\D{1}\d{9}\D{2}$|^9\d{15,21}$| ^91[0-9]+$| ^[A-Za-z]{2}[0-9]+US$/i'; $matchFedex1 = '/(\b96\d{20}\b)|(\b\d{15}\b)|(\b\d{12}\b)/'; $matchFedex2 = '/\b((98\d\d\d\d\d?\d\d\d\d|98\d\d) ?\d\d\d\d ?\d\d\d\d( ?\d\d\d)?)\b/'; $matchFedex3 = '/^[0-9]{15}$/'; if(preg_match($matchUPS1, $trackingNumber) || preg_match($matchUPS2, $trackingNumber)) { echo('UPS'); $carrier = 'UPS'; return $carrier; } else if(preg_match($matchUSPS0, $trackingNumber) || preg_match($matchUSPS1, $trackingNumber) || preg_match($matchUSPS2, $trackingNumber) || preg_match($matchUSPS3, $trackingNumber) || preg_match($matchUSPS4, $trackingNumber) || preg_match($matchUSPS5, $trackingNumber)) { $carrier = 'USPS'; return $carrier; } else if (preg_match($matchFedex1, $trackingNumber) || preg_match($matchFedex2, $trackingNumber) || preg_match($matchFedex3, $trackingNumber)) { $carrier = 'FedEx'; return $carrier; } else if (0){ $carrier = 'DHL'; return $carrier; } return; } </code></pre> <br /><br /><br /><h3>回答5:</h3><br /><p>You can try these (not guaranteed):</p> <p>UPS:</p> <pre><code>\b(1Z ?[0-9A-Z]{3} ?[0-9A-Z]{3} ?[0-9A-Z]{2} ?[0-9A-Z]{4} ?[0-9A-Z]{3} ?[0-9A-Z]|[\dT]\d\d\d ?\d\d\d\d ?\d\d\d)\b </code></pre> <p>UPS:</p> <pre><code>\b(1Z ?\d\d\d ?\d\w\w ?\d\d ?\d\d\d\d ?\d\d\d ?\d|[\dT]\d\d\d ?\d\d\d\d ?\d\d\d)\b </code></pre> <p>USPost:</p> <pre><code>\b(\d\d\d\d ?\d\d\d\d ?\d\d\d\d ?\d\d\d\d ?\d\d\d\d ?\d\d|\d\d\d\d ?\d\d\d\d ?\d\d\d\d ?\d\d\d\d ?\d\d\d\d)\b </code></pre> <p>But please test before you use them. I recommend RegexBuddy.</p> <br /><br /><br /><h3>回答6:</h3><br /><p>Been researching this for a while, and made these based mostly on the answers here.<br /> These should cover everything, without being too lenient.<br /> UPS:<br /><code>/^(1Z\s?[0-9A-Z]{3}\s?[0-9A-Z]{3}\s?[0-9A-Z]{2}\s?[0-9A-Z]{4}\s?[0-9A-Z]{3}\s?[0-9A-Z]$|[\dT]\d{3}\s?\d{4}s?\d{3})$/i</code></p> <p>USPS:<br /><code>/^(EA|EC|CP|RA)\d{9}(\D{2})?$|^(7\d|03|23|91)\d{2}\s?\d{4}\s?\d{4}\s?\d{4}\s?\d{4}(\s\d{2})?$|^82\s?\d{3}\s?\d{3}\s?\d{2}$/i</code></p> <p>FEDEX:<br /><code>/^(((96|98)\d{5}\s?\d{4}$|^(96|98)\d{2})\s?\d{4}\s?\d{4}(\s?\d{3})?)$/i</code></p> <br /><br /><br /><h3>回答7:</h3><br /><p>I use these in an eBay application I wrote:</p> <p><strong>USPS Domestic:</strong></p> <pre><code>/^91[0-9]+$/ </code></pre> <p><strong>USPS International:</strong></p> <pre><code>/^[A-Za-z]{2}[0-9]+US$/ </code></pre> <p><strong>FedEx:</strong></p> <pre><code>/^[0-9]{15}$/ </code></pre> <p>However, this might be eBay/Paypal specific, as all USPS Domestic labels start with "91". All USPS International labels start with two characters and end with "US". As far as I know, FedEx just uses 15 random digits.</p> <p>(Please note that these regular expressions assume all spaces are removed. It would be fairly easy to allow for spaces though)</p> <br /><br /><br /><h3>回答8:</h3><br /><p>In the event it helps anyone else searching for this, here is a simple Python class that resolves common formats: Gist #541851</p> <br /><br /><br /><h3>回答9:</h3><br /><p>Check out this github project that lists a lot of PHP tracking regexes. https://github.com/darkain/php-tracking-urls</p> <br /><br /><br /><h3>回答10:</h3><br /><p>Here are the ones I am now using in my Java app. These are determined by my experience of sucking tracking numbers out of shipping confirmation emails from a whole pile of drop ship services. I just made a new USPS one from scratch since none of the ones I found worked for some of my numbers based on example numbers on the USPS site. These only work for US tracking codes because we only sell in the US. </p> <pre><code>private final Pattern UPS_TRACKING_NUMBER = Pattern.compile("[^A-Za-z0-9](1Z[A-Za-z0-9]{6,})", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); private final Pattern FEDEX_TRACKING_NUMBER = Pattern.compile("\\b((96|98)\\d{18,20}|\\d{15}|\\d{12})\\b", Pattern.MULTILINE); private final Pattern USPS_TRACKING_NUMBER = Pattern.compile("\\b(9[2-4]\\d{20}(?:(?:EA|RA)\\d{9}US)?|(?:03|23|14|70)\\d{18})\\b", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); </code></pre> <br /><br /><br /><h3>回答11:</h3><br /><p>I'm working in an Angular2+ app and just put together a component to handle common US tracking numbers. It tests them using standard JavaScript RegExp's that I put together from this resource HERE &amp; HERE and sets the href on an anchor tag with the tracking link URL if it's good. You don't have to be using Angular or TypeScript to easily adapt this to your application. I tested it out with different dummy numbers and seem to work dynamically so far. Please note, you can also switch out the null in the last else statement with the in-line commented url and it will send you to a Google search. </p> <p>Any feedback (or if your tracking numbers don't work) please let me know I will update the answer. Thanks!</p> <p>USAGE IN HTML:</p> <p><code>&lt;app-tracking-number [trackNum]="myTrackingNumberInput"&gt;&lt;/app-tracking-number&gt;</code></p> <p>COMPONENT .TS</p> <pre><code>import { Component, OnInit, Input } from '@angular/core'; @Component({ selector: 'app-tracking-number', templateUrl: './tracking-number.component.html', styleUrls: ['./tracking-number.component.scss'] }) export class TrackingNumberComponent implements OnInit { @Input() trackNum:string; trackNumHref:string = null; // Carrier tracking numbers patterns from https://www.iship.com/trackit/info.aspx?info=24 AND https://www.canadapost.ca/web/en/kb/details.page?article=how_to_track_a_packa&amp;cattype=kb&amp;cat=receiving&amp;subcat=tracking isUPS:RegExp = new RegExp('^1Z[A-H,J-N,P,R-Z,0-9]{16}$'); // UPS tracking numbers usually begin with "1Z", contain 18 characters, and do not contain the letters "O", "I", or "Q". isFedEx:RegExp = new RegExp('^[0-9]{12}$|^[0-9]{15}$'); // FedEx Express tracking numbers are normally 12 digits long and do not contain letters AND FedEx Ground tracking numbers are normally 15 digits long and do not contain letters. isUSPS:RegExp = new RegExp('^[0-9]{20,22}$|^[A-Z]{2}[0-9,A-Z]{9}US$'); // USPS Tracking numbers are normally 20-22 digits long and do not contain letters AND USPS Express Mail tracking numbers are normally 13 characters long, begin with two letters, and end with "US". isDHL:RegExp = new RegExp('^[0-9]{10,11}$'); // DHL tracking numbers are normally 10 or 11 digits long and do not contain letters. isCAPost:RegExp = new RegExp('^[0-9]{16}$|^[A-Z]{2}[0-9]{9}[A-Z]{2}$'); // 16 numeric digits (0000 0000 0000 0000) AND 13 numeric and alphabetic characters (AA 000 000 000 AA). constructor() { } ngOnInit() { this.setHref(); } setHref() { if(!this.trackNum) this.trackNumHref = null; else if(this.isUPS.test(this.trackNum)) this.trackNumHref = `https://wwwapps.ups.com/WebTracking/processInputRequest?AgreeToTermsAndConditions=yes&amp;loc=en_US&amp;tracknum=${this.trackNum}&amp;Requester=trkinppg`; else if(this.isFedEx.test(this.trackNum)) this.trackNumHref = `https://www.fedex.com/apps/fedextrack/index.html?tracknumber=${this.trackNum}`; else if(this.isUSPS.test(this.trackNum)) this.trackNumHref = `https://tools.usps.com/go/TrackConfirmAction?tLabels=${this.trackNum}`; else if(this.isDHL.test(this.trackNum)) this.trackNumHref = `http://www.dhl.com/en/express/tracking.html?AWB=${this.trackNum}&amp;brand=DHL`; else if(this.isCAPost.test(this.trackNum)) this.trackNumHref =`https://www.canadapost.ca/trackweb/en#/search?searchFor=${this.trackNum}`; else this.trackNumHref = null; // Google search as fallback... `https://www.google.com/search?q=${this.trackNum}`; } } </code></pre> <p>COMPONENT .HTML</p> <pre><code>&lt;a *ngIf="trackNumHref" [href]="trackNumHref" target="_blank"&gt;{{trackNum}}&lt;/a&gt; &lt;span *ngIf="!trackNumHref"&gt;{{trackNum}}&lt;/span&gt; </code></pre> <br /><br /><br /><h3>回答12:</h3><br /><p>I believe FedEx is 12 digits:</p> <pre><code>^[0-9]{12}$ </code></pre> <br /><br /><br /><h3>回答13:</h3><br /><p>I also came across tracking numbers from FedEx with 22 digits recently, so watch out! I haven't found any good reference for the FedEx's general format yet.</p> <p>FedEx Example #: 9612019059803563050071</p> <br /><br /><br /><h3>回答14:</h3><br /><p>Here's an up to date regex for UPS (works with regular and Mail Innovation type tracking numbers):</p> <p>\b(1Z ?[0-9A-Z]{3} ?[0-9A-Z]{3} ?[0-9A-Z]{2} ?[0-9A-Z]{4} ?[0-9A-Z]{3} ?[0-9A-Z]|[\dT]\d\d\d ?\d\d\d\d ?\d\d\d|\d\d\d ?\d\d\d ?\d\d\d|\d{22,34})\b</p> <br /><br /><br /><h3>回答15:</h3><br /><p>Late to the party however, the below will work with 26 char USPS numbers as well.</p> <pre><code>/(\b\d{30}\b)|(\b91\d+\b)|(\b\d{20}\b)|(\b\d{26}\b)|^E\D{1}\d{9}\D{2}$|^9\d{15,21}$|^91[0-9]+$|^[A-Za-z]{2}[0-9]+US$/i </code></pre> <br /><br /><br /><h3>回答16:</h3><br /><p>I know there are already lots of answers and that this was asked a long time ago, but I don't see a single one that addresses all the possible USPS tracking numbers with a single expression.</p> <p>Here is what I came up with:</p> <pre><code>((\d{4})(\s?\d{4}){4}\s?\d{2})|((\d{2})(\s?\d{3}){2}\s?\d{2})|((\D{2})(\s?\d{3}){3}\s?\D{2}) </code></pre> <p>See it working here: http://regexr.com/3e61u</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/619977/regular-expression-patterns-for-tracking-numbers</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/regex" hreflang="zh-hans">regex</a></div> <div class="field--item"><a href="/tag/fedex" hreflang="zh-hans">fedex</a></div> <div class="field--item"><a href="/tag/ups" hreflang="zh-hans">ups</a></div> </div> </div> Sat, 28 Dec 2019 18:32:49 +0000 余生颓废 2981255 at https://www.e-learn.cn UPS epl label show on web page https://www.e-learn.cn/topic/2925511 <span>UPS epl label show on web page</span> <span><span lang="" about="/user/40" typeof="schema:Person" property="schema:name" datatype="">こ雲淡風輕ζ</span></span> <span>2019-12-25 05:19:06</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I am using ue UPS shipment API ...</p> <pre><code>&lt;LabelSpecification&gt; &lt;LabelStockSize&gt; &lt;Height&gt;4&lt;/Height&gt; &lt;Width&gt;6&lt;/Width&gt; &lt;/LabelStockSize&gt; &lt;LabelPrintMethod&gt; &lt;Code&gt;EPL&lt;/Code&gt; &lt;Description&gt;epl file&lt;/Description&gt; &lt;/LabelPrintMethod&gt; &lt;HTTPUserAgent&gt;Mozilla/4.5&lt;/HTTPUserAgent&gt; &lt;LabelImageFormat&gt; &lt;Code&gt;GIF&lt;/Code&gt; &lt;Description&gt;gif&lt;/Description&gt; &lt;/LabelImageFormat&gt; &lt;/LabelSpecification&gt; </code></pre> <p>. . .</p> <p>it's return raw format of image like STgsQSwwMDEKSTgsQSwwMDEKT0QKcTc5NQpRMTYwMCwyNApTMgpEMTAKSkYKTgpaVApiMTMsNDI5LE0sIjAxNSw4NDAsMTk0MDYsMDAwMCxbKT4eMDEdOTYxWjk0NjM4NzYzHVVQU04dNDRBQTE1HjA3L1RNRjItODIlKVFNKE1VQloyMDcpWEoyK0JORUlZOEorXCJcDVEgLBxZJDhEXA1cDR4EIgpBMTcsNywwLDIsMSwxLE4sIlRFU1QiCkExNywyNCwwLDIsMSwxLE4sIjExMS0xMTEtMTExMSIKQTE3LDQxLDAsMiwxLDEsTiwiMTE1MCBGSVJTVCBBVkUiCkExNyw1OCwwLDIsMSwxLE4sIktJTkcgT0YgUFJVU1NJQSAgUEEgMTk0MDYiCkE2MiwxNjQAAAAP/////....</p> <p>I want to know how can I save the image to my pc and to show it on the web page.</p> <br /><h3>回答1:</h3><br /><p>I succeed in php, using fopen and fwrite to create a gif file,such as </p> <pre><code>$file=fopen("temp.gif","w"); fwrite($file,base64_decode("the encoded string...")); </code></pre> <p>this will get a gif file,then you can put it on the web.Remenber to chown the folder where you save the gif file with apache:apache.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>Not familiar with UPS API but USPS returns label data base64 encoded. Maybe try and use the function base64_decode and then file_put_contents to save to disk. </p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/11535698/ups-epl-label-show-on-web-page</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/php" hreflang="zh-hans">php</a></div> <div class="field--item"><a href="/tag/ups" hreflang="zh-hans">ups</a></div> </div> </div> Tue, 24 Dec 2019 21:19:06 +0000 こ雲淡風輕ζ 2925511 at https://www.e-learn.cn UPS API - printing the returned shipping label GIF data https://www.e-learn.cn/topic/2891481 <span>UPS API - printing the returned shipping label GIF data</span> <span><span lang="" about="/user/99" typeof="schema:Person" property="schema:name" datatype="">牧云@^-^@</span></span> <span>2019-12-24 17:24:30</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>So I'm working my way through the UPS API 'create shipping label' process...I'm at the final stage, where having validated everything, UPS return the actual shipping label to me in GIF format, from their example document, here's what is returned via XML (I've edited out all the other preceding XML bits)..</p> <pre><code>&lt;GraphicImage&gt;FSDJHSDJHJ3487EHNE9U8DY9VHRFV89SDFHFSDJHFSDIDFH SJKDFSJKDFSJIU9GFIUGJIFDUJG9UKGLDJFDKJDGKJDFKGDJLDFKSJGKDFJDKGFDG9E0ER IJGE39IWURE9U9ER0UW9R0UR9WEGU9URE9WGUW90U90GRUG90GERUG9REUGWERGJIO JGIODFGUIOFDUGIOFUIGRUE090U9TERUT90RUT9EU90ERUT9ERU9EUER9TUT9R0UTE90R U9TERU90RTEU9SDKHGJHGDFU&lt;/GraphicImage&gt; &lt;HTMLImage&gt;SKJJKLHGIGKHGKJHGFJGFJHDFJGHDDJFHFDJHFJHFJKDHJK FDHJFJDFHDFJHJDFHGJDHGDFSHJKFSDHSDFJHFJSDHJKDFHFJKSHDSKJHGFDJSJDFSKSK JJKLHGIGKHGKJHGFJGFJHDFJGHDDJFHFDJHFJHFJKDHJKFDHJFJDFHDFJHJDFHGJDHGDF SHJKFSDHSDFJHFJSDHJKDFHFJKSHDSKJHGFDJSJDFSKHGJKDS&lt;/HTMLImage&gt; </code></pre> <p>..what am I meant to do with either that GIF data or that HTMLIMage data? For example I piped the GIF data into a gif file - but the GIF file won't open - is there something else I need to do?</p> <br /><h3>回答1:</h3><br /><p>Most shipping API's return labels as Base 64 encoded strings (in JSON or XML). You'll need to convert the content from base 64 to an bite array, and save it. </p> <p>The way you do the Base64 conversion varies by development platform, but there are plenty of examples. Here's one I just found.</p> <p>http://processrhetoric.blogspot.com/2013/01/getting-ups-shipping-label-via-their-api.html</p> <p>If you use the Google Chrome browser, you can preview the image by building a string that starts with </p> <pre><code>data:image/gif;base64, </code></pre> <p>Then add the image content (though your example content doesn't seem to work).</p> <pre><code>data:image/gif;base64,FSDJHSDJHJ3487EHNE9U8DY9VHRFV89SDFHFSDJHFSDIDFH SJKDFSJKDFSJIU9GFIUGJIFDUJG9UKGLDJFDKJDGKJDFKGDJLDFKSJGKDFJDKGFDG9E0ER IJGE39IWURE9U9ER0UW9R0UR9WEGU9URE9WGUW90U90GRUG90GERUG9REUGWERGJIO JGIODFGUIOFDUGIOFUIGRUE090U9TERUT90RUT9EU90ERUT9ERU9EUER9TUT9R0UTE90R U9TERU90RTEU9SDKHGJHGDFU </code></pre> <p>And put the results in the browser address bar, and the image will appear.</p> <p>In JavaScript / VBScript, use ADODB to save the bytes that you create from base64 to disk as a GIF.</p> <pre><code>var stream = new ActiveXObject("ADODB.Stream"); try { if (objFSO.FileExists(strFileName)) { objFSO.DeleteFile(strFileName); } stream.Type = 2; // text stream.Charset = "ISO-8859-1"; stream.Open(); stream.WriteText(bytes); stream.SaveToFile( strFileName, 2); } catch (err){ return; } finally { if (stream.State != 0) { stream.Close(); } } </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><pre><code>For this we need two gems: gem "wicked_pdf" gem 'wkhtmltopdf-binary' ups_gif_image = base64 GIF image # This is the base64 graphicimage in the form of GIF that is returned from UPS shipment request API ups_base64_gif_image ="data:image/gif;base64,"+ups_gif_image pdf_data = WickedPdf.new.pdf_from_string("&lt;img src='"+ups_base64_gif_image+"'/&gt;",{:orientation =&gt; 'Landscape'}) File.open('label.pdf','wb') do |pdf| pdf.write pdf_data pdf.close end </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/50986453/ups-api-printing-the-returned-shipping-label-gif-data</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/xml" hreflang="zh-hans">xml</a></div> <div class="field--item"><a href="/tag/gif" hreflang="zh-hans">gif</a></div> <div class="field--item"><a href="/tag/shipping" hreflang="zh-hans">shipping</a></div> <div class="field--item"><a href="/tag/ups" hreflang="zh-hans">ups</a></div> </div> </div> Tue, 24 Dec 2019 09:24:30 +0000 牧云@^-^@ 2891481 at https://www.e-learn.cn How to solve JSON Syntax error. How to get response? https://www.e-learn.cn/topic/2863281 <span>How to solve JSON Syntax error. How to get response?</span> <span><span lang="" about="/user/179" typeof="schema:Person" property="schema:name" datatype="">不羁岁月</span></span> <span>2019-12-24 07:45:17</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>This is the UPS shipping webservices API. I am getting this error :</p> <blockquote> <p>{"Error":{"Code":"4","Description":"JSON Syntax error"}}</p> </blockquote> <p><strong>AJAX Code:</strong> </p> <pre><code> &lt;script&gt; var formData = { "UPSSecurity": { "UsernameToken": { "Username":"xxx.com", "Password":"xxxxx" }, "ServiceAccessToken": { "AccessLicenseNumber":"1234D567DF67" } }, "RateRequest": { "Request": { "RequestOption":"Rate", "TransactionReference": { "CustomerContext":"Test saran" } }, "Shipment": { "Shipper": { "Name":"Saravanan", "ShipperNumber":"Y72A41", "Address": { "AddressLine":["2311 York Rd"], "City":"Sebastopol", "StateProvinceCode":"CA", "PostalCode":"95473", "CountryCode":"US" } }, "ShipTo": { "Name":"ShipToName", "Address": { "AddressLine":["195 N main st"], "City":"Sebastopol", "StateProvinceCode":"CA", "PostalCode":"95472", "CountryCode":"US" } }, "ShipFrom": { "Name":"ShipFromName", "Address": { "AddressLine":"2311 York Rd", "City":"Sebastopol","StateProvinceCode":"CA", "PostalCode":"95473", "CountryCode":"US" } }, "Service": { "Code":"03", "Description":"Express" }, "Package": { "PackagingType": { "Code": "02", "Description": "Rate" }, "Dimensions": { "UnitOfMeasurement": { "Code": "IN", "Description": "inches" }, "Length": "7", "Width": "5", "Height": "2" }, "PackageWeight": { "UnitOfMeasurement": { "Code": "Lbs", "Description": "pounds" }, "Weight": "10" } }, "ShipmentRatingOptions": { "NegotiatedRatesIndicator": "" } } } }; $.ajax({ type : "POST", url : "https://wwwcie.ups.com/rest/Rate", crossDomain: true, timeout : 240000, data : formData, dataType : 'json', success : function(response) { alert("result="+response); } }); &lt;/script&gt; </code></pre> <p>I don't know where I am wrong. But this request is running perfectly by "POST MAN" and "ARC" tools. Please update answer.</p> <br /><h3>回答1:</h3><br /><p>You're not sending JSON; jQuery's default serialization when you give it an object is URI-encoding. To send JSON instead, convert your object to a string with <code>JSON.stringify</code>. You should also identify that what you're sending is JSON using <code>contentType</code>, so:</p> <pre><code>contentType: 'application/json', data : JSON.stringify(formData), </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/40084851/how-to-solve-json-syntax-error-how-to-get-response</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/php" hreflang="zh-hans">php</a></div> <div class="field--item"><a href="/tag/json" hreflang="zh-hans">json</a></div> <div class="field--item"><a href="/tag/ups" hreflang="zh-hans">ups</a></div> </div> </div> Mon, 23 Dec 2019 23:45:17 +0000 不羁岁月 2863281 at https://www.e-learn.cn