PluginProbe
Welcart e-Commerce / 2.12.3
Welcart e-Commerce v2.12.3
2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 All 291 releases
usc-e-shop / classes / paymentPaygent.module.class.php

paymentPaygent.module.class.php in Welcart e-Commerce 2.12.3, at classes/paymentPaygent.module.class.php

1,756 lines 41.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ペイジェント決済モジュール
4 *
5 * @package Welcart
6 * @author Collne Inc.
7 * @since 2.2.6
8 * @version 1.0.0
9 */
10
11 /**
12 * Paygent Module.
13 *
14 * @package Welcart
15 * @author Collne Inc.
16 * @since 2.2.6
17 */
18 class Paygent_Module {
19
20 /**
21 * Instance of this class.
22 *
23 * @var object
24 */
25 protected static $instance = null;
26
27 /**
28 * マーチャントID
29 *
30 * @var string
31 */
32 protected $merchant_id;
33
34 /**
35 * 接続ID
36 *
37 * @var string
38 */
39 protected $connect_id;
40
41 /**
42 * 接続パスワード
43 *
44 * @var string
45 */
46 protected $connect_password;
47
48 /**
49 * クライアント証明書ファイル
50 *
51 * @var string
52 */
53 protected $client_file;
54
55 /**
56 * CA証明書ファイル
57 *
58 * @var string
59 */
60 protected $ca_file;
61
62 /**
63 * 電文バージョン
64 *
65 * @var string
66 */
67 protected $telegram_version;
68
69 /**
70 * カナ変換用 要求電文POSTパラメータ名
71 *
72 * @var array
73 */
74 protected $replace_kana_param = array(
75 'customer_family_name_kana',
76 'customer_name_kana',
77 'payment_detail_kana',
78 'claim_kana',
79 'receipt_name_kana',
80 );
81
82 /**
83 * カナ変換用 応答電文パラメータ名
84 *
85 * @var array
86 */
87 public static $encording_kana_param = array(
88 'customer_family_name',
89 'customer_name',
90 'customer_family_name_kana',
91 'customer_name_kana',
92 'payment_detail',
93 'payment_detail_kana',
94 'claim_kanji',
95 'claim_kana',
96 'acq_name',
97 'issur_name',
98 'receipt_name_kana',
99 'description',
100 'store_name',
101 'buyer_name_kanji',
102 'buyer_name_kana',
103 'shipping_address_state',
104 'shipping_address_city',
105 'shipping_address_line2',
106 'shipping_address_line1',
107 'order_items_id',
108 'order_items_title',
109 'order_items_description',
110 );
111
112 /**
113 * Shift_JIS変換用 応答電文パラメータ名
114 *
115 * @var array
116 */
117 public static $encording_sjis_param = array(
118 'customer_family_name',
119 'customer_name',
120 'customer_family_name_kana',
121 'customer_name_kana',
122 'payment_detail',
123 'payment_detail_kana',
124 'claim_kanji',
125 'claim_kana',
126 'acq_name',
127 'issur_name',
128 'receipt_name_kana',
129 );
130
131 /**
132 * UTF-8対象電文
133 *
134 * @var array
135 */
136 public static $telegram_kind_utf8 = array(
137 '098',
138 '380',
139 '410',
140 '411',
141 '412',
142 '413',
143 '414',
144 '415',
145 '416',
146 '417',
147 '450',
148 );
149
150 /**
151 * �
152 �会電文
153 *
154 * @var array
155 */
156 protected $telegram_kind_ref = array(
157 '027',
158 '090',
159 );
160
161 /**
162 * �
163 �会MAX件数
164 *
165 * @var int
166 */
167 protected $select_max_cnt;
168
169 /**
170 * 電文パラメータ
171 *
172 * @var array
173 */
174 protected $telegram_param = array();
175
176 /**
177 * 通信処理
178 *
179 * @var object
180 */
181 protected $sender;
182
183 /**
184 * 文字コード
185 *
186 * @var string
187 */
188 protected $encoding = '';
189
190 /**
191 * 処理結果
192 *
193 * @var object
194 */
195 protected $response_data;
196
197 /**
198 * 処理結果メッセージ
199 *
200 * @var string
201 */
202 protected $result_message = '';
203
204 /**
205 * 処理結果ステータス
206 *
207 * @var string
208 */
209 protected $result_status;
210
211 /**
212 * レスポンスコード
213 *
214 * @var string
215 */
216 protected $response_code;
217
218 /**
219 * レスポンス詳細
220 *
221 * @var array
222 */
223 protected $response_detail;
224
225 /**
226 * データ
227 *
228 * @var array
229 */
230 protected $data;
231
232 /**
233 * 解析対象データ
234 *
235 * @var int
236 */
237 protected $line;
238
239 /**
240 * 次の読み出し開始位置
241 *
242 * @var int
243 */
244 protected $current_pos;
245
246 /**
247 * 最終読込み位置
248 *
249 * @var int
250 */
251 protected $max_pos;
252
253 /**
254 * 動作環境
255 *
256 * @var boolean
257 */
258 protected $testmode;
259
260 /**
261 * データヘッダー
262 *
263 * @var array
264 */
265 protected $data_header;
266
267 /**
268 * Construct.
269 */
270 public function __construct() {
271 $acting_settings = $this->get_acting_settings();
272 $this->testmode = ( 'test' === $acting_settings['ope'] );
273 $this->merchant_id = $acting_settings['seq_merchant_id'];
274 $this->connect_id = $acting_settings['connect_id'];
275 $this->connect_password = $acting_settings['connect_password'];
276 $this->client_file = $acting_settings['certificate_path'] . '/' . $acting_settings['client_file'];
277 $this->ca_file = $acting_settings['certificate_path'] . '/' . $acting_settings['ca_file'];
278 $this->telegram_version = TELEGRAM_VERSION;
279 $this->select_max_cnt = 2000;
280 $this->encoding = 'UTF-8';
281 $this->telegram_param = array();
282 }
283
284 /**
285 * Return an instance of this class.
286 */
287 public static function get_instance() {
288 if ( is_null( self::$instance ) ) {
289 self::$instance = new self();
290 }
291 return self::$instance;
292 }
293
294 /**
295 * �
296 �通ヘッダを設定
297 */
298 public function set_req_header() {
299 $this->telegram_param['merchant_id'] = $this->merchant_id;
300 $this->telegram_param['connect_id'] = $this->connect_id;
301 $this->telegram_param['connect_password'] = $this->connect_password;
302 $this->telegram_param['telegram_version'] = $this->telegram_version;
303 }
304
305 /**
306 * 引数初期化
307 */
308 public function init() {
309 $this->telegram_param = array();
310 $this->data = array();
311 $this->data_header = array();
312 $this->response_data = null;
313 $this->result_message = '';
314 $this->result_status = '';
315 $this->response_code = '';
316 $this->response_detail = '';
317 }
318
319 /**
320 * 引数を設定
321 *
322 * @param string $key Key.
323 * @param string $value Value.
324 */
325 public function req_put( $key, $value ) {
326 $temp_val = $value;
327 if ( null === $temp_val ) {
328 // Value 値の null 設定は認めない.
329 $temp_val = '';
330 }
331 $this->telegram_param[ $key ] = $temp_val;
332 }
333
334 /**
335 * 引数を取得
336 *
337 * @param string $key Key.
338 * @return string
339 */
340 public function req_get( $key ) {
341 return $this->telegram_param[ $key ];
342 }
343
344 /**
345 * 処理結果取得
346 *
347 * @return array
348 */
349 public function get_response_data() {
350 return $this->response_data;
351 }
352
353 /**
354 * 処理結果メッセージ取得
355 *
356 * @return array
357 */
358 public function get_result_message() {
359 return $this->result_message;
360 }
361
362 /**
363 * 処理結果ステータス取得
364 *
365 * @return string
366 */
367 public function get_result_status() {
368 return $this->result_status;
369 }
370
371 /**
372 * レスポンスコード取得
373 *
374 * @return array
375 */
376 public function get_response_code() {
377 return $this->response_code;
378 }
379
380 /**
381 * レスポンス詳細取得
382 *
383 * @return array
384 */
385 public function get_response_detail() {
386 return $this->response_detail;
387 }
388
389 /**
390 * 要求電文POST処理
391 *
392 * @param string $telegram_kind 電文種別ID.
393 * @return mixed
394 */
395 public function post( $telegram_kind ) {
396
397 // �
398 �通ヘッダ設定.
399 $this->set_req_header();
400 $this->telegram_param['telegram_kind'] = $telegram_kind;
401
402 // URL取得.
403 $url = $this->get_url( $telegram_kind );
404 if ( TEREGRAM_PARAM_OUTSIDE_ERROR == $url ) {
405 return TEREGRAM_PARAM_OUTSIDE_ERROR;
406 }
407
408 // Https_Request_Sender 取得.
409 $this->sender = new Https_Request_Sender( $url );
410
411 // クライアント証明書パス設定.
412 $this->sender->set_client_certificate_path( $this->client_file );
413
414 // CA証明書パス設定.
415 $this->sender->set_ca_certificate_path( $this->ca_file );
416
417 // カナ変換処理.
418 $this->replace_telegram_kana();
419
420 // エンコード処理.
421 $this->encording_request_param();
422
423 // 電文長チェック.
424 $telegram_length = $this->sender->get_telegram_length( $this->telegram_param );
425 if ( TELEGRAM_LENGTH < $telegram_length ) {
426 return TEREGRAM_PARAM_REQUIRED_ERROR;
427 }
428
429 // Post.
430 $rslt = $this->sender->post_request_body( $this->telegram_param );
431 if ( ! ( true === $rslt ) ) {
432 $this->result_message = $this->sender->get_result_message();
433 return $rslt;
434 }
435
436 // Get Response.
437 $res_body = $this->sender->get_response_body();
438
439 // Create Response Data.
440 $this->response_data = $this->create_response_data( $res_body, $telegram_kind );
441
442 $this->result_message = $this->get_response_code() . ': ' . $this->get_response_detail();
443
444 return $rslt;
445 }
446
447 /**
448 * ResponseData を作成
449 *
450 * @param array $res_body 処理結果.
451 * @param string $telegram_kind 電文種別ID.
452 * @return object
453 */
454 public function create_response_data( $res_body, $telegram_kind ) {
455 $response_data = null;
456 if ( in_array( $telegram_kind, $this->telegram_kind_ref, true ) ) {
457 $res = $this->parse_reference( $res_body, $telegram_kind );
458 if ( $res ) {
459 $response_data = current( $this->data );
460 }
461 } else {
462 $res = $this->parse_payment( $res_body, $telegram_kind );
463 if ( $res ) {
464 $response_data = current( $this->data );
465 }
466 }
467 return $response_data;
468 }
469
470 /**
471 * 接続�
472 �URLを取得
473 *
474 * @param string $telegram_kind 電文種別ID.
475 * @return string FALSE: 失敗(TEREGRAM_PARAM_OUTSIDE_ERROR)、成功:取得した URL
476 */
477 public function get_url( $telegram_kind ) {
478 $url = null;
479 if ( $this->testmode ) {
480 switch ( $telegram_kind ) {
481 case PAYGENT_CREDIT: // カード決済オーソリ.
482 case PAYGENT_AUTH_CANCEL: // カード決済オーソリキャンセル.
483 case PAYGENT_CARD_COMMIT: // カード決済売上.
484 case PAYGENT_CARD_COMMIT_CANCEL: // カード決済売上キャンセル.
485 case PAYGENT_CARD_COMMIT_AUTH_REVISE: // カード決済補正オーソリ.
486 case PAYGENT_CARD_COMMIT_REVISE: // カード決済補正売上.
487 case PAYGENT_CARD_STOCK_SET: // カード�
488 報設定.
489 case PAYGENT_CARD_STOCK_DEL: // カード�
490 報削除.
491 case PAYGENT_CARD_STOCK_GET: // カード�
492 報�
493 �会.
494 $url = 'https://sandbox.paygent.co.jp/n/card/request';
495 break;
496 case PAYGENT_CARD_3DS2: // 3Dセキュア2.0認証.
497 $url = 'https://sandbox.paygent.co.jp/n/threeds/request';
498 break;
499 case PAYGENT_CONVENI_NUM: // コンビニ決済(番号方式)申込.
500 $url = 'https://sandbox.paygent.co.jp/n/conveni/request';
501 break;
502 case PAYGENT_ATM: // ATM決済.
503 $url = 'https://sandbox.paygent.co.jp/n/atm/request';
504 break;
505 case PAYGENT_BANK: // 銀行ネット決済.
506 $url = 'https://sandbox.paygent.co.jp/n/bank/request';
507 break;
508 case PAYGENT_BANK_ASP: // 銀行ネット決済ASP申込.
509 $url = 'https://sandbox.paygent.co.jp/n/bank/requestasp';
510 break;
511 case PAYGENT_PAIDY_AUTH_CANCEL: // Paidyオーソリキャンセル.
512 case PAYGENT_PAIDY_CAPTURE: // Paidy売上.
513 case PAYGENT_PAIDY_REFUND: // Paidy返金.
514 case PAYGENT_PAIDY_REF: // Paidy決済�
515 報検証.
516 $url = 'https://sandbox.paygent.co.jp/n/paidy/request';
517 break;
518 case PAYGENT_DIFF_REF: // 決済�
519 報差分�
520 �会.
521 $url = 'https://sandbox.paygent.co.jp/n/ref/paynotice';
522 break;
523 case PAYGENT_REF: // 決済�
524 報�
525 �会.
526 $url = 'https://sandbox.paygent.co.jp/n/ref/paymentref';
527 break;
528 }
529 } else {
530 switch ( $telegram_kind ) {
531 case PAYGENT_CREDIT: // カード決済オーソリ.
532 case PAYGENT_AUTH_CANCEL: // カード決済オーソリキャンセル.
533 case PAYGENT_CARD_COMMIT: // カード決済売上.
534 case PAYGENT_CARD_COMMIT_CANCEL: // カード決済売上キャンセル.
535 case PAYGENT_CARD_COMMIT_AUTH_REVISE: // カード決済補正オーソリ.
536 case PAYGENT_CARD_COMMIT_REVISE: // カード決済補正売上.
537 case PAYGENT_CARD_STOCK_SET: // カード�
538 報設定.
539 case PAYGENT_CARD_STOCK_DEL: // カード�
540 報削除.
541 case PAYGENT_CARD_STOCK_GET: // カード�
542 報�
543 �会.
544 $url = 'https://module.paygent.co.jp/n/card/request';
545 break;
546 case PAYGENT_CARD_3DS2: // 3Dセキュア2.0認証.
547 $url = 'https://module.paygent.co.jp/n/threeds/request';
548 break;
549 case PAYGENT_CONVENI_NUM: // コンビニ決済(番号方式)申込.
550 $url = 'https://module.paygent.co.jp/n/conveni/request';
551 break;
552 case PAYGENT_ATM: // ATM決済.
553 $url = 'https://module.paygent.co.jp/n/atm/request';
554 break;
555 case PAYGENT_BANK: // 銀行ネット決済.
556 $url = 'https://module.paygent.co.jp/n/bank/request';
557 break;
558 case PAYGENT_BANK_ASP: // 銀行ネット決済ASP申込.
559 $url = 'https://module.paygent.co.jp/n/bank/requestasp';
560 break;
561 case PAYGENT_PAIDY_AUTH_CANCEL: // Paidyオーソリキャンセル.
562 case PAYGENT_PAIDY_CAPTURE: // Paidy売上.
563 case PAYGENT_PAIDY_REFUND: // Paidy返金.
564 case PAYGENT_PAIDY_REF: // Paidy決済�
565 報検証.
566 $url = 'https://module.paygent.co.jp/n/paidy/request';
567 break;
568 case PAYGENT_DIFF_REF: // 決済�
569 報差分�
570 �会.
571 $url = 'https://module.paygent.co.jp/n/ref/paynotice';
572 break;
573 case PAYGENT_REF: // 決済�
574 報�
575 �会.
576 $url = 'https://module.paygent.co.jp/n/ref/paymentref';
577 break;
578 }
579 }
580 if ( empty( $url ) ) {
581 $url = TEREGRAM_PARAM_OUTSIDE_ERROR;
582 }
583 return $url;
584 }
585
586 /**
587 * 要求電文パラメータ 半角カナ 置換処理
588 */
589 public function replace_telegram_kana() {
590 foreach ( $this->telegram_param as $key => $value ) {
591 if ( in_array( strtolower( $key ), $this->replace_kana_param ) ) {
592 $this->telegram_param[ $key ] = String_Utitily::convert_katakana_zen2han( $value );
593 }
594 }
595 }
596
597 /**
598 * 要求電文パラメータ エンコード処理
599 */
600 public function encording_request_param() {
601 foreach ( $this->telegram_param as $key => $value ) {
602 if ( in_array( strtolower( $key ), self::$encording_sjis_param ) ) {
603 $this->telegram_param[ $key ] = String_Utitily::convert_encoding_sjis( $value );
604 }
605 }
606 }
607
608 /**
609 * 応答電文パラメータ エンコード処理
610 *
611 * @param string $data パラメータ.
612 * @return string
613 */
614 public static function encording_response_kana( $data ) {
615 foreach ( $data as $key => $value ) {
616 // if ( in_array( strtolower( $key ), self::$encording_kana_param ) ) {
617 // $data[ $key ] = String_Utitily::convert_encoding_utf8( $value );
618 // }
619 foreach ( self::$encording_kana_param as $encording_kana ) {
620 $pos = strpos( strtolower( $key ), $encording_kana );
621 if ( false !== $pos ) {
622 $data[ $key ] = String_Utitily::convert_encoding_utf8( $value );
623 }
624 }
625 }
626 return $data;
627 }
628
629 /**
630 * 応答電文を分解
631 *
632 * @param array $body レスポンスボディ.
633 * @param string $telegram_kind 電文種別ID.
634 * @return boolean TRUE: 成功、他:エラーコード
635 */
636 public function parse_payment( $body, $telegram_kind ) {
637
638 // 保持データを初期化.
639 $map = array();
640
641 // "_html" キー存在フラグ.
642 $html_key_flg = false;
643
644 // "_htmk" キー値.
645 $html_key = '';
646
647 // "_html" キー出現以後のデータ保持.
648 $html_value = '';
649
650 $lines = explode( LINE_SEPARATOR, $body );
651
652 foreach ( $lines as $i => $line ) {
653 $line_item = String_Utitily::split( $line, PROPERTIES_REGEX, PROPERTIES_REGEX_COUNT );
654
655 // 読込終了.
656 $tmp_len = strlen( $line_item[0] ) - strlen( HTML_ITEM );
657 if ( 0 <= $tmp_len && strpos( $line_item[0], HTML_ITEM, $tmp_len ) === $tmp_len ) {
658 // Key が "_html" の場合.
659 $html_key = $line_item[0];
660 $html_key_flg = true;
661 }
662 if ( $html_key_flg ) {
663 if ( ! ( strlen( $line_item[0] ) - strlen( HTML_ITEM ) >= 0 && strpos( $line_item[0], HTML_ITEM, strlen( $line_item[0] ) - strlen( HTML_ITEM ) ) === strlen( $line_item[0] ) - strlen( HTML_ITEM ) ) ) {
664 // "_html" Key が読み取られた場合.
665 $html_value .= $line;
666 $html_value .= LINE_SEPARATOR;
667 }
668 } else {
669 if ( 1 < count( $line_item ) ) {
670 if ( RESPONSEDATA_RESULT == $line_item[0] ) {
671 // 処理結果を設定.
672 $this->result_status = $line_item[1];
673 } elseif ( RESPONSEDATA_RESPONSE_CODE == $line_item[0] ) {
674 // レスポンスコードを設定.
675 $this->response_code = $line_item[1];
676 } elseif ( RESPONSEDATA_RESPONSE_DETAIL == $line_item[0] ) {
677 // レスポンス詳細を設定.
678 if ( in_array( $telegram_kind, self::$telegram_kind_utf8 ) ) {
679 $this->response_detail = $line_item[1];
680 } else {
681 $this->response_detail = String_Utitily::convert_encoding_utf8( $line_item[1] );
682 }
683 } else {
684 // Mapに設定.
685 $map[ $line_item[0] ] = $line_item[1];
686 }
687 }
688 }
689 }
690
691 if ( $html_key_flg ) {
692 // "_html" Key が出現した場合、設定.
693 if ( strlen( LINE_SEPARATOR ) <= strlen( $html_value ) ) {
694 if ( strpos( $html_value, LINE_SEPARATOR, strlen( $html_value ) - strlen( LINE_SEPARATOR ) ) === strlen( $html_value ) - strlen( LINE_SEPARATOR ) ) {
695 $html_value = substr( $html_value, 0, strlen( $html_value ) - strlen( LINE_SEPARATOR ) );
696 }
697 }
698 $map[ $html_key ] = $html_value;
699 }
700
701 if ( 0 < count( $map ) ) {
702 // Map が設定されている場合.
703 $map = self::encording_response_kana( $map );
704 $this->data[] = $map;
705 }
706
707 if ( String_Utitily::is_empty( $this->result_status ) ) {
708 // 処理結果が 空文字 もしくは null の場合.
709 return false;
710 }
711
712 return true;
713 }
714
715 /**
716 * ResponseData を分解
717 *
718 * @param array $body レスポンス.
719 * @param string $telegram_kind 電文種別ID.
720 * @return mixed TRUE:成功、他:エラーコード
721 */
722 public function parse_reference( $body, $telegram_kind ) {
723
724 // 保持データを初期化.
725 $map = array();
726
727 $lines = explode( LINE_SEPARATOR, $body );
728
729 foreach ( $lines as $i => $line ) {
730 $line_item = $this->parse_csv_data( $line );
731 $line_item_cnt = count( $line_item );
732 if ( 0 < $line_item_cnt ) {
733 if ( LINENO_HEADER == $line_item[ LINE_RECORD_DIVISION ] ) {
734 // ヘッダー部の行の場合.
735 if ( LINE_HEADER_RESULT < $line_item_cnt ) {
736 // 処理結果を設定.
737 $this->result_status = $line_item[ LINE_HEADER_RESULT ];
738 }
739 if ( LINE_HEADER_RESPONSE_CODE < $line_item_cnt ) {
740 // レスポンスコードを設定.
741 $this->response_code = $line_item[ LINE_HEADER_RESPONSE_CODE ];
742 }
743 if ( LINE_HEADER_RESPONSE_DETAIL < $line_item_cnt ) {
744 // レスポンス詳細を設定.
745 if ( in_array( $telegram_kind, self::$telegram_kind_utf8 ) ) {
746 $this->response_detail = $line_item[ LINE_HEADER_RESPONSE_DETAIL ];
747 } else {
748 $this->response_detail = String_Utitily::convert_encoding_utf8( $line_item[ LINE_HEADER_RESPONSE_DETAIL ] );
749 }
750 }
751 } elseif ( LINENO_DATA_HEADER == $line_item[ LINE_RECORD_DIVISION ] ) {
752 // データヘッダー部の行の場合.
753 $this->data_header = array();
754 for ( $i = 1; $i < $line_item_cnt; $i++ ) {
755 // データヘッダーを設定(レコード区分は除く).
756 $this->data_header[] = $line_item[ $i ];
757 }
758 } elseif ( LINENO_DATA == $line_item[ LINE_RECORD_DIVISION ] ) {
759 // データ部の行の場合.
760 // データヘッダー部が既に展開済みである事を想定.
761 $map = array();
762
763 if ( count( $this->data_header ) == ( $line_item_cnt - 1 ) ) {
764 // データヘッダー数と、データ�
765 目数(レコード区分除く)は一致.
766 for ( $i = 1; $i < $line_item_cnt; $i++ ) {
767 // 対応するデータヘッダーを Key に、Mapへ設定.
768 $map[ $this->data_header[ $i - 1 ] ] = $line_item[ $i ];
769 }
770 } else {
771 // データヘッダー数と、データ�
772 目数が一致しない場合.
773 return false;
774 }
775
776 if ( 0 < count( $map ) ) {
777 // Map が設定されている場合.
778 $map = self::encording_response_kana( $map );
779 $this->data[] = $map;
780 }
781 } elseif ( LINENO_TRAILER == $line_item[ LINE_RECORD_DIVISION ] ) {
782 // トレーラー部の行の場合.
783 if ( LINE_TRAILER_DATA_COUNT < $line_item_cnt ) {
784 // データサイズ.
785 }
786 }
787 }
788 }
789
790 if ( String_Utitily::is_empty( $this->result_status ) ) {
791 // 処理結果が 空文字 もしくは null の場合.
792 return false;
793 }
794
795 return true;
796 }
797
798 /**
799 * CSVデータ文字列から�
800 目データ�
801 �列を取得する
802 *
803 * @param string $line 解析対象文字列(1行分のデータ).
804 * @return array データ�
805 �列
806 */
807 private function parse_csv_data( $line ) {
808 if ( false == isset( $line ) ) {
809 return array();
810 }
811
812 $this->line = $line;
813 $this->max_pos = strlen( $this->line );
814 $this->current_pos = 0;
815
816 // �
817 目データを格納する.
818 $items = array();
819 // 囲み文字あり/なしの状�
820 �判定フラグ.
821 $exist_envelope = false;
822
823 while ( $this->current_pos <= $this->max_pos ) {
824 // データ区切り位置を取得する.
825 $end_pos = $this->get_end_position( $this->current_pos );
826 // 1�
827 目分のデータを読み取る.
828 $temp = substr( $line, $this->current_pos, $end_pos - $this->current_pos );
829 $temp_cnt = strlen( $temp );
830
831 $work = '';
832 // �
833 目データなしの場合.
834 if ( 0 == $temp_cnt ) {
835 $work = '';
836 } else {
837 // 囲い文字があるかチェックする.
838 if ( CSV_DEF_ITEM_ENVELOPE == $temp[0] ) {
839 $exist_envelope = true;
840 }
841
842 $is_data = false;
843 for ( $i = 0; $i < $temp_cnt; ) {
844 $chr_tmp = $temp[ $i ];
845 if ( $exist_envelope && CSV_DEF_ITEM_ENVELOPE == $temp[ $i ] ) {
846 $i++;
847 if ( $is_data ) {
848 if ( ( $i < strlen( $temp ) ) && ( CSV_DEF_ITEM_ENVELOPE == $temp[ $i ] ) ) {
849 // 囲み文字が2つ続けて現れたときは、文字データとして取得する.
850 $work .= $temp[ $i++ ];
851 } else {
852 $is_data = ! $is_data;
853 }
854 } else {
855 $is_data = ! $is_data;
856 }
857 } else {
858 $work .= $temp[ $i++ ];
859 }
860 }
861 }
862 // 1�
863 目分のデータを登録する.
864 $items[] = $work;
865
866 // 次の読取位置の更新.
867 $this->current_pos = $end_pos + 1;
868 }
869 return $items;
870 }
871
872 /**
873 * データ区切り位置を返す
874 *
875 * @param int $start 検索開始位置.
876 * @return int 1データの区切り位置を返す
877 */
878 private function get_end_position( $start ) {
879
880 // 文字列/文字列外の状�
881 �判定フラグ.
882 $state = false;
883 // 囲み文字あり/なしの状�
884 �判定フラグ.
885 $exist_envelope = false;
886 // 読み込んだ文字.
887 $ch = null;
888 // 区切り位置.
889 $end = 0;
890
891 if ( $start >= $this->max_pos ) {
892 return $start;
893 }
894
895 // 囲み文字の有無判定.
896 if ( CSV_DEF_ITEM_ENVELOPE == $this->line[ $start ] ) {
897 $exist_envelope = true;
898 }
899
900 $end = $start;
901
902 while ( $end < $this->max_pos ) {
903 // 1文字読み込む.
904 $ch = $this->line[ $end ];
905 // 文字の判定.
906 if ( false == $state && CSV_DEF_SEPARATOR == $ch ) {
907 // 文字列中の区切り文字でなければ、データ区切り.
908 break;
909 } elseif ( $exist_envelope && CSV_DEF_ITEM_ENVELOPE == $ch ) {
910 // 囲み文字が現れたら、文字列/文字列外の状�
911 �判定を反転.
912 if ( $state ) {
913 $state = false;
914 } else {
915 $state = true;
916 }
917 }
918 // 文字位置のカウントアップ.
919 $end++;
920 }
921 return $end;
922 }
923
924 /**
925 * 決済オプション取得
926 *
927 * @return array
928 */
929 private function get_acting_settings() {
930 global $usces;
931
932 $acting_settings = ( isset( $usces->options['acting_settings']['paygent'] ) ) ? $usces->options['acting_settings']['paygent'] : array();
933 return $acting_settings;
934 }
935 }
936
937 /**
938 * Https Request Sender.
939 *
940 * @package Welcart
941 * @author Collne Inc.
942 * @since 2.3
943 */
944 class Https_Request_Sender {
945
946 /**
947 * KeyStore Password
948 *
949 * @var string
950 */
951 protected $keystore_password = 'changeit';
952
953 /**
954 * レスポンスヘッダ
955 *
956 * @var object
957 */
958 protected $response_header = null;
959
960 /**
961 * レスポンスボディ
962 *
963 * @var object
964 */
965 protected $response_body = null;
966
967 /**
968 * ステータスコード
969 *
970 * @var string
971 */
972 protected $status_code;
973
974 /**
975 * 接続�
976 � URL
977 *
978 * @var string
979 */
980 protected $url;
981
982 /**
983 * クライアント証明書パス
984 *
985 * @var string
986 */
987 protected $client_certificate_path;
988
989 /**
990 * 認証局証明書パス
991 *
992 * @var string
993 */
994 protected $ca_certificate_path;
995
996 /**
997 * SSL通信用ソケット
998 *
999 * @var object
1000 */
1001 protected $ch;
1002
1003 /**
1004 * タイムアウト値
1005 *
1006 * @var int
1007 */
1008 protected $timeout;
1009
1010 /**
1011 * 処理結果メッセージ
1012 *
1013 * @var string
1014 */
1015 protected $result_message = '';
1016
1017 /**
1018 * コンストラクタ
1019 * 接続�
1020 �URLを設定
1021 *
1022 * @param string $url 接続�
1023 �URL.
1024 */
1025 public function __construct( $url ) {
1026 $this->url = $url;
1027 $this->response_body = null;
1028 $this->response_header = null;
1029 $this->timeout = 35;
1030 }
1031
1032 /**
1033 * クライアント証明書パスを設定
1034 *
1035 * @param string $file_name クライアント証明書パス.
1036 */
1037 public function set_client_certificate_path( $file_name ) {
1038 $this->client_certificate_path = $file_name;
1039 }
1040
1041 /**
1042 * 認証局証明書パスを設定
1043 *
1044 * @param string $file_name 認証局証明書パス.
1045 */
1046 public function set_ca_certificate_path( $file_name ) {
1047 $this->ca_certificate_path = $file_name;
1048 }
1049
1050 /**
1051 * 処理結果メッセージ
1052 *
1053 * @return string
1054 */
1055 public function get_result_message() {
1056 return $this->result_message;
1057 }
1058
1059 /**
1060 * Postを実施
1061 *
1062 * @param array $form_data Map.
1063 * @return mixed TRUE:成功、他:エラーコード
1064 */
1065 public function post_request_body( $form_data ) {
1066 // 通信開始.
1067 $this->init_curl();
1068
1069 // リクエストを送信.
1070 $ret_code = $this->send( $form_data );
1071
1072 // レスポンスを受信.
1073 $this->close_curl();
1074 return $ret_code;
1075 }
1076
1077 /**
1078 * 受信データを返す
1079 *
1080 * @return string
1081 */
1082 public function get_response_body() {
1083 return $this->response_body;
1084 }
1085
1086 /**
1087 * 電文長取得
1088 *
1089 * @param string $form_data 電文.
1090 * @return int 電文長(byte)
1091 */
1092 public function get_telegram_length( $form_data ) {
1093 if ( null == $form_data ) {
1094 return 0;
1095 }
1096
1097 $sb = $this->url;
1098 $sb .= '?';
1099 foreach ( $form_data as $key => $value ) {
1100 $sb .= $key;
1101 $sb .= '=';
1102 $sb .= $value;
1103 $sb .= '&';
1104 }
1105
1106 $rs = '';
1107 if ( 0 < strlen( $sb ) ) {
1108 $rs = substr( $sb, 0, strlen( $sb ) - 1 );
1109 }
1110 return strlen( $rs );
1111 }
1112
1113 /**
1114 * 要求電文を作成
1115 *
1116 * @param array $form_data 要求電文.
1117 * @return string 作成した要求電文(URL)
1118 */
1119 public function convert2urlencoded_string( $form_data ) {
1120 if ( null == $form_data ) {
1121 return '';
1122 }
1123
1124 $encoded_string = '';
1125 foreach ( $form_data as $key => $value ) {
1126 $tmp = $key;
1127 $encoded_string .= urlencode( $tmp );
1128 $encoded_string .= '=';
1129 $tmp = $value;
1130 $encoded_string .= urlencode( $tmp );
1131 $encoded_string .= '&';
1132 }
1133
1134 $rs = '';
1135 if ( 0 < strlen( $encoded_string ) ) {
1136 $rs = substr( $encoded_string, 0, strlen( $encoded_string ) - 1 );
1137 }
1138 return $rs;
1139 }
1140
1141 /**
1142 * 接続のための初期化処理
1143 *
1144 * @return mixed
1145 */
1146 public function init_curl() {
1147 $rslt = true;
1148
1149 // 初期化.
1150 $this->ch = curl_init( $this->url );
1151
1152 $rslt = $rslt && curl_setopt( $this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 );
1153 $rslt = $rslt && curl_setopt( $this->ch, CURLOPT_RETURNTRANSFER, true );
1154 $rslt = $rslt && curl_setopt( $this->ch, CURLOPT_POST, true );
1155 $rslt = $rslt && curl_setopt( $this->ch, CURLOPT_HEADER, true );
1156
1157 // 証明書.
1158 $rslt = $rslt && curl_setopt( $this->ch, CURLOPT_SSL_VERIFYHOST, false );
1159
1160 // クライアント証明書.
1161 $rslt = $rslt && curl_setopt( $this->ch, CURLOPT_SSLCERT, $this->client_certificate_path );
1162 $rslt = $rslt && curl_setopt( $this->ch, CURLOPT_SSLKEYPASSWD, $this->keystore_password );
1163
1164 // CA証明書.
1165 $rslt = $rslt && curl_setopt( $this->ch, CURLOPT_SSL_VERIFYPEER, true );
1166 $rslt = $rslt && curl_setopt( $this->ch, CURLOPT_CAINFO, $this->ca_certificate_path );
1167
1168 // タイムアウト.
1169 $rslt = $rslt && curl_setopt( $this->ch, CURLOPT_TIMEOUT, $this->timeout );
1170
1171 return $rslt;
1172 }
1173
1174 /**
1175 * リクエスト生成と送信
1176 *
1177 * @param array $form_data Map 要求電文.
1178 * @return mixed TRUE:成功、他:エラーコード
1179 */
1180 public function send( $form_data ) {
1181 // リクエストを Map から String に変換.
1182 $query = $this->convert2urlencoded_string( $form_data, false );
1183
1184 $header = array();
1185 $header[] = 'Content-Type=application/x-www-form-urlencoded';
1186 $header[] = 'charset=Windows-31J';
1187 $header[] = 'Content-Length: ' . ( String_Utitily::is_empty( $query ) ? '0' : strlen( $query ) );
1188 $header[] = 'User-Agent: curl_php';
1189 curl_setopt( $this->ch, CURLOPT_HTTPHEADER, $header );
1190 curl_setopt( $this->ch, CURLOPT_POSTFIELDS, $query );
1191
1192 $str = curl_exec( $this->ch );
1193 if ( false === $str && 0 != curl_errno( $this->ch ) ) {
1194 return $this->proc_error();
1195 }
1196 $ret_code = $this->parse_response( $str );
1197 return $ret_code;
1198 }
1199
1200 /**
1201 * Curl のエラー処理
1202 *
1203 * @return mixed True:問題なし、他:エラーコード
1204 */
1205 public function proc_error() {
1206 $error_no = curl_errno( $this->ch );
1207 $error_msg = $error_no . ': ' . curl_error( $this->ch );
1208 $ret_code = true;
1209
1210 if ( CURLE_COULDNT_CONNECT >= $error_no ) {
1211 // 接続問題.
1212 $ret_code = KS_CONNECT_ERROR;
1213 } elseif ( CURLE_COULDNT_CONNECT == $error_no ) {
1214 // 接続問題.
1215 $ret_code = KS_CONNECT_ERROR;
1216 } elseif ( CURLE_SSL_CERTPROBLEM == $error_no ) {
1217 // 認証問題.
1218 $ret_code = CERTIFICATE_ERROR;
1219 } elseif ( CURLE_SSL_CACERT == $error_no ) {
1220 // 認証問題.
1221 $ret_code = CERTIFICATE_ERROR;
1222 } elseif ( CURLE_SSL_CACERT_BADFILE == $error_no ) {
1223 // 認証問題.
1224 $ret_code = CERTIFICATE_ERROR;
1225 } elseif ( CURLE_HTTP_RETURNED_ERROR == $error_no ) {
1226 // HTTP Return code error.
1227 $ret_code = KS_CONNECT_ERROR;
1228 } else {
1229 // その他のエラー.
1230 $ret_code = KS_CONNECT_ERROR;
1231 }
1232 $this->result_message = $ret_code . ': ' . $error_msg;
1233
1234 // 証明書ファイルの状�
1235 �チェック.
1236 if ( ! file_exists( $this->client_certificate_path ) ) {
1237 $this->result_message .= '(file is not exists: ' . $this->client_certificate_path . ')';
1238 } elseif ( ! is_readable( $this->client_certificate_path ) ) {
1239 $this->result_message .= '(file is not readable: ' . $this->client_certificate_path . ')';
1240 }
1241 if ( ! file_exists( $this->ca_certificate_path ) ) {
1242 $this->result_message .= '(file is not exists: ' . $this->ca_certificate_path . ')';
1243 } elseif ( ! is_readable( $this->ca_certificate_path ) ) {
1244 $this->result_message .= '(file is not readable: ' . $this->ca_certificate_path . ')';
1245 }
1246 return $ret_code;
1247 }
1248
1249 /**
1250 * レスポンスを受信
1251 *
1252 * @param string $data レスポンス文字列.
1253 * @return mixed TRUE:成功、他:エラーコード
1254 */
1255 public function parse_response( $data ) {
1256
1257 // レスポンス受信.
1258 $line = null;
1259 $ret_code = HTTP_STATUS_INIT_VALUE;
1260 $res_body_start = 0;
1261 $lines = explode( LINE_SEPARATOR, $data );
1262
1263 // ヘッダまでを読み込む.
1264 foreach ( $lines as $i => $line ) {
1265 if ( String_Utitily::is_empty( $line ) ) {
1266 break;
1267 }
1268 $res_body_start += strlen( $line ) + strlen( LINE_SEPARATOR );
1269 if ( HTTP_STATUS_INIT_VALUE === $ret_code ) {
1270 // ステータスの解析.
1271 $ret_code = $this->parse_status_line( $line );
1272 if ( true === $ret_code ) {
1273 continue;
1274 }
1275 return $ret_code;
1276 }
1277 // ヘッダの解析.
1278 if ( ! $this->parse_response_header( $line ) ) {
1279 continue;
1280 }
1281 }
1282
1283 $info = curl_getinfo( $this->ch );
1284 // linuxサーバでheader_sizeに誤った値が設定される事象が見られたためsize_downloadでキャプチャしている.
1285 $res_body_start = -( $info['size_download'] );
1286 $this->response_body = substr( $data, $res_body_start );
1287
1288 return true;
1289 }
1290
1291 /**
1292 * ステータスラインを解析
1293 * (HTTP-Version SP Status-Code SP Reason-Phrase CRLF)
1294 *
1295 * @param string $line ステータスライン.
1296 * @return mixed TRUE:成功、他:エラーコード
1297 */
1298 public function parse_status_line( $line ) {
1299 if ( String_Utitily::is_empty( $line ) ) {
1300 // 不正なステータスコードを受け取った.
1301 return KS_CONNECT_ERROR;
1302 }
1303
1304 $status_line = String_Utitily::split( $line, ' ', 3 );
1305
1306 if ( String_Utitily::is_numeric( $status_line[1] ) ) {
1307 // 不正なステータスコードを受け取った.
1308 $this->status_code = intval( $status_line[1] );
1309 } else {
1310 return KS_CONNECT_ERROR;
1311 }
1312 if ( strpos( $status_line[0], 'HTTP/' ) != 0 || ! String_Utitily::is_numeric_length( $status_line[1], 3 ) ) {
1313 // 不正なステータスコードを受け取った.
1314 return KS_CONNECT_ERROR;
1315 }
1316 if ( ! ( ( 200 <= $this->status_code ) && ( $this->status_code <= 206 ) ) ) {
1317 // HTTP Status が Success Code (200 - 206) でない場合.
1318 return KS_CONNECT_ERROR;
1319 }
1320 return true;
1321 }
1322
1323 /**
1324 * レスポンスヘッダを一行解析して、�
1325 部に格納
1326 * レスポンスヘッダの値が存在しない場合は、nullを設定
1327 *
1328 * @param string $line サーバから受け取ったレスポンス行.
1329 * @return boolean true=ヘッダ解析・格納完了, false=ヘッダではない(ヘッダ部終了)
1330 */
1331 public function parse_response_header( $line ) {
1332 if ( String_Utitily::is_empty( $line ) ) {
1333 // HEADER終了.
1334 return false;
1335 }
1336
1337 // HEADER.
1338 $header_str = String_Utitily::split( $line, ':', 2 );
1339 if ( null == $this->response_header ) {
1340 $this->response_header = array();
1341 }
1342 if ( 1 == count( $header_str ) || 0 == strlen( trim( $header_str[1] ) ) ) {
1343 // 値が存在しない or 値が空文字列.
1344 $this->response_header[ $header_str[0] ] = null;
1345 } else {
1346 $this->response_header[ $header_str[0] ] = trim( $header_str[1] );
1347 }
1348 return true;
1349 }
1350
1351 /**
1352 * Close curl
1353 */
1354 public function close_curl() {
1355 // プロキシソケットCLOSE.
1356 if ( null != $this->ch ) {
1357 curl_close( $this->ch );
1358 $this->ch = null;
1359 }
1360 }
1361 }
1362
1363 /**
1364 * String Utitily.
1365 *
1366 * @package Welcart
1367 * @author Collne Inc.
1368 * @since 2.3
1369 */
1370 class String_Utitily {
1371
1372 /**
1373 * �
1374 �通で変換するカタカナ文字列のマッピング�
1375 報を格納しているマップ
1376 *
1377 * @var array
1378 */
1379 protected $katakana_map = array();
1380
1381 /**
1382 * 使用可能な�
1383 �角カタカナ
1384 *
1385 * @var array
1386 */
1387 protected $zen_kana = array(
1388 '',
1389 '',
1390 '',
1391 '',
1392 '',
1393 '',
1394 '',
1395 '',
1396 '',
1397 '',
1398 '',
1399 '',
1400 '',
1401 '',
1402 /*'ソ', */
1403 '',
1404 '',
1405 '',
1406 '',
1407 '',
1408 '',
1409 '',
1410 '',
1411 '',
1412 '',
1413 '',
1414 '',
1415 '',
1416 '',
1417 '',
1418 '',
1419 '',
1420 '',
1421 '',
1422 '',
1423 '',
1424 '',
1425 '',
1426 '',
1427 '',
1428 '',
1429 '',
1430 '',
1431 '',
1432 '',
1433 '',
1434 '',
1435 '',
1436 '',
1437 '',
1438 '',
1439 '',
1440 '',
1441 '',
1442 '',
1443 '',
1444 '',
1445 '',
1446 '�
1447 ',
1448 '',
1449 '',
1450 '',
1451 '',
1452 '',
1453 '',
1454 '',
1455 '',
1456 '',
1457 '',
1458 '',
1459 '',
1460 '',
1461 '',
1462 '',
1463 '',
1464 '',
1465 '',
1466 '',
1467 '',
1468 '',
1469 '',
1470 '',
1471 );
1472
1473 /**
1474 * 使用可能な半角カタカナ
1475 *
1476 * @var array
1477 */
1478 protected $han_kana = array(
1479 '',
1480 '',
1481 '',
1482 '',
1483 '',
1484 '',
1485 '',
1486 '',
1487 '',
1488 '',
1489 '',
1490 '',
1491 '',
1492 '',
1493 'ソ',
1494 '',
1495 '',
1496 '',
1497 '',
1498 '',
1499 '�
1500 ',
1501 '',
1502 '',
1503 '',
1504 '',
1505 '',
1506 '',
1507 '',
1508 '',
1509 '',
1510 '',
1511 '',
1512 '',
1513 '',
1514 '',
1515 '',
1516 '',
1517 '',
1518 '',
1519 '',
1520 '',
1521 '',
1522 '',
1523 '',
1524 '',
1525 '',
1526 'ガ',
1527 'ギ',
1528 'グ',
1529 'ゲ',
1530 'ゴ',
1531 'ザ',
1532 'ジ',
1533 'ズ',
1534 'ゼ',
1535 'ゾ',
1536 'ダ',
1537 'ヂ',
1538 'ヅ',
1539 'デ',
1540 'ド',
1541 'バ',
1542 'ビ',
1543 'ブ',
1544 'ベ',
1545 'ボ',
1546 'ヴ',
1547 'パ',
1548 'ピ',
1549 'プ',
1550 'ペ',
1551 'ポ',
1552 '',
1553 '',
1554 '',
1555 '',
1556 '',
1557 '',
1558 '',
1559 '',
1560 '',
1561 '',
1562 );
1563
1564 /**
1565 * Construct.
1566 */
1567 public function __construct() {
1568 $zen_kana_cnt = count( $this->zen_kana );
1569 if ( $zen_kana_cnt == count( $this->katakana_map ) ) {
1570 return;
1571 }
1572 for ( $i = 0; $i < $zen_kana_cnt; $i++ ) {
1573 $this->katakana_map[ $this->zen_kana[ $i ] ] = $this->han_kana[ $i ];
1574 }
1575 }
1576
1577 /**
1578 * パラメータが null または空文字かを判断する
1579 *
1580 * @param string $str 判定する文字列.
1581 * @return boolean nullまたは空文字の場合、true
1582 */
1583 public static function is_empty( $str ) {
1584 return ( ! isset( $str ) || strlen( trim( $str ) ) <= 0 );
1585 }
1586
1587 /**
1588 * Split(分割数制限版)
1589 *
1590 * @param string $str 分割対象文字列.
1591 * @param string $delim 区切り文字.
1592 * @param int $limit 結果の閾値.
1593 * @return array 分割後の文字�
1594 �列
1595 */
1596 public static function split( $str, $delim, $limit = -1 ) {
1597 $delim_len = strlen( $delim );
1598 $pos = 0;
1599 $index = 0;
1600 $list = array();
1601 if ( 0 != $delim_len ) {
1602 while ( ! ( ( $index = strpos( $str, $delim, $pos ) ) === false ) ) {
1603 $list[] = substr( $str, $pos, $index - $pos );
1604 $pos = $index + $delim_len;
1605 if ( $pos >= strlen( $str ) ) {
1606 break;
1607 }
1608 }
1609 if ( $pos == strlen( $str ) ) {
1610 $list[] = ''; // the last is the delimiter.
1611 } elseif ( $pos < strlen( $str ) ) {
1612 $list[] = substr( $str, $pos );
1613 }
1614 } else {
1615 $str_len = strlen( $str );
1616 for ( $i = 0; $i < $str_len; $i++ ) {
1617 $c = $str[ $i ];
1618 $list[] = '' . $c;
1619 }
1620 }
1621
1622 $rs = &$list;
1623
1624 $rs_cnt = count( $rs );
1625 if ( ( 0 < $limit ) && ( $limit < $rs_cnt ) ) {
1626 // limit より、分割数が多い場合、分割数を limit に合わせる.
1627 $temp = array();
1628 $pos = 0;
1629 for ( $i = 0; $i < $limit - 1; $i++ ) {
1630 $temp[] = $rs[ $i ];
1631 $pos += strlen( $rs[ $i ] ) + $delim_len;
1632 }
1633 $temp[ $limit - 1 ] = substr( $str, $pos );
1634 for ( $i = $limit; $i < $rs_cnt; $i++ ) {
1635 $sb = $temp[ $limit - 1 ];
1636 }
1637 $rs = $temp;
1638 }
1639 return $rs;
1640 }
1641
1642 /**
1643 * 数値判定
1644 *
1645 * @param string $str 数値判定対象文字列.
1646 * @return boolean true=数値 false=数値以外
1647 */
1648 public static function is_numeric( $str ) {
1649 $rb = is_numeric( $str );
1650 return $rb;
1651 }
1652
1653 /**
1654 * 数値、桁数判定
1655 *
1656 * @param string $str 数値判定対象文字列.
1657 * @param int $len 判定対象 Length.
1658 * @return boolean true=桁数�
1659 数値 false=数値でない or 桁数違い
1660 */
1661 public static function is_numeric_length( $str, $len ) {
1662 $rb = false;
1663 if ( self::is_numeric( $str ) ) {
1664 if ( strlen( $str ) == $len ) {
1665 $rb = true;
1666 }
1667 }
1668 return $rb;
1669 }
1670
1671 /**
1672 * �
1673 �角カタカナ文字を半角カタカナの該当文字に変換する
1674 * 指定された文字列がnullの場合はnullを返す
1675 *
1676 * @param string $src 変換する�
1677 �の文字列.
1678 * @return string 変換後の文字列
1679 */
1680 public static function convert_katakana_zen2han( $src ) {
1681 if ( null == $src ) {
1682 return null;
1683 }
1684 $str = mb_convert_kana( $src, 'kV', 'UTF-8' );
1685 return $str;
1686 }
1687
1688 /**
1689 * 指定された文字列を指定されたマッピング�
1690 報に基づき変換した結果の文字列を返す
1691 * 指定された文字列が null の場合は null を返す
1692 *
1693 * @param string $src 変換する�
1694 �の文字列.
1695 * @param array $convert_map 変換の対象となる文字と変換後のマッピング�
1696 報を格納しているマップ.
1697 * @return string 変換後の文字列
1698 */
1699 public static function convert( $src, $convert_map ) {
1700 if ( null == $src ) {
1701 return null;
1702 }
1703 $result = '';
1704 $chars = $this->to_chars( $src );
1705 foreach ( $chars as $c ) {
1706 if ( array_key_exists( $c, $convert_map ) ) {
1707 $result .= $convert_map[ $c ];
1708 } else {
1709 $result .= $c;
1710 }
1711 }
1712 return $result;
1713 }
1714
1715 /**
1716 * 文字列を1文字づつ�
1717 �列に変換
1718 *
1719 * @param string $str 変換する�
1720 �の文字列.
1721 * @return array
1722 */
1723 public static function to_chars( $str ) {
1724 $str_len = mb_strlen( $str );
1725 $chars = array();
1726 for ( $i = 0; $i < $str_len; $i++ ) {
1727 $out = mb_substr( $str, $i, 1 );
1728 $chars[] = $out;
1729 $intx = 0;
1730 }
1731 return $chars;
1732 }
1733
1734 /**
1735 * UTF8にエンコードする
1736 *
1737 * @param string $string エンコード前の文字列.
1738 * @return string エンコード後の文字列
1739 */
1740 public static function convert_encoding_utf8( $string ) {
1741 $string = mb_convert_encoding( $string, 'UTF-8', 'sjis-win' );
1742 return $string;
1743 }
1744
1745 /**
1746 * Shift_JISにエンコードする
1747 *
1748 * @param string $string エンコード前の文字列.
1749 * @return string エンコード後の文字列
1750 */
1751 public static function convert_encoding_sjis( $string ) {
1752 $string = mb_convert_encoding( $string, 'sjis-win', 'UTF-8' );
1753 return $string;
1754 }
1755 }
1756