@@ -26,9 +26,10 @@ function phoneid ($phone_number, array $fields = []) {
26
26
}
27
27
28
28
protected function execute ($ method_name , $ resource , $ fields = [], $ date = null , $ nonce = null ) {
29
- print ("\n********PHONEID********* \n" );
30
29
$ json_fields = json_encode ($ fields );
31
30
31
+ $ content_type = in_array ($ method_name , ["POST " , "PUT " ]) ? "application/json " : "" ;
32
+
32
33
$ headers = $ this ->generateTelesignHeaders (
33
34
$ this ->customer_id ,
34
35
$ this ->api_key ,
@@ -37,7 +38,8 @@ protected function execute ($method_name, $resource, $fields = [], $date = null,
37
38
$ json_fields ,
38
39
$ date ,
39
40
$ nonce ,
40
- $ this ->user_agent
41
+ $ this ->user_agent ,
42
+ $ content_type
41
43
);
42
44
43
45
$ option = in_array ($ method_name , [ "POST " , "PUT " ]) ? "body " : "query " ;
@@ -48,63 +50,5 @@ protected function execute ($method_name, $resource, $fields = [], $date = null,
48
50
"http_errors " => false
49
51
]));
50
52
}
51
-
52
- static function generateTelesignHeaders (
53
- $ customer_id ,
54
- $ api_key ,
55
- $ method_name ,
56
- $ resource ,
57
- $ url_encoded_fields ,
58
- $ date = null ,
59
- $ nonce = null ,
60
- $ user_agent = null
61
- ) {
62
- if (!$ date ) {
63
- $ date = gmdate ("D, d M Y H:i:s T " );
64
- }
65
-
66
- if (!$ nonce ) {
67
- $ nonce = Uuid::uuid4 ()->toString ();
68
- }
69
-
70
- $ content_type = in_array ($ method_name , ["POST " , "PUT " ]) ? "application/json " : "" ;
71
-
72
- $ auth_method = "HMAC-SHA256 " ;
73
-
74
- $ string_to_sign_builder = [
75
- $ method_name ,
76
- "\n$ content_type " ,
77
- "\n$ date " ,
78
- "\nx-ts-auth-method: $ auth_method " ,
79
- "\nx-ts-nonce: $ nonce "
80
- ];
81
-
82
- if ($ content_type && $ url_encoded_fields ) {
83
- $ string_to_sign_builder [] = "\n$ url_encoded_fields " ;
84
- }
85
-
86
- $ string_to_sign_builder [] = "\n$ resource " ;
87
-
88
- $ string_to_sign = join ("" , $ string_to_sign_builder );
89
-
90
- $ signature = base64_encode (
91
- hash_hmac ("sha256 " , utf8_encode ($ string_to_sign ), base64_decode ($ api_key ), true )
92
- );
93
- $ authorization = "TSA $ customer_id: $ signature " ;
94
-
95
- $ headers = [
96
- "Authorization " => $ authorization ,
97
- "Date " => $ date ,
98
- "Content-Type " => $ content_type ,
99
- "x-ts-auth-method " => $ auth_method ,
100
- "x-ts-nonce " => $ nonce
101
- ];
102
-
103
- if ($ user_agent ) {
104
- $ headers ["User-Agent " ] = $ user_agent ;
105
- }
106
-
107
- return $ headers ;
108
- }
109
53
110
54
}
0 commit comments