管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
/ ^2 i" ~" J1 I$ n1.添加商品信息
0 h$ [8 ]* |: ?. {2.添加图片# q( B" z; t3 V8 W r7 i2 n
3.查询所有产品
5 Y; {+ W1 H, f: T' Z( R4.查询某个具体产品信息
3 E( X$ G& N! X' c! _ |9 ?/ @5.删除某个产品
" g+ Q- N. B& r! j: [: ^/ M6.删除图片) Z$ t' H% G! l1 P
7.图像识别
) |% b) x& H, c; D5 i6 `' o: k/ b) U8 r4 z: U4 ~( `) U0 I
图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey/ h# l+ V5 u& E( F3 k7 \
5 z5 A7 m* C# q9 w9 _" Z
PHP示例:+ o w5 Y6 n8 J" B. z5 h. x
- <!--?php7 {0 o# G0 K0 C8 {9 r
- // +----------------------------------------------------------------------
. u' a9 L0 s8 v# ^2 H - // | JuhePHP [ NO ZUO NO DIE ]
# w6 h0 x7 [, o T+ Y - // +---------------------------------------------------------------------- U, H5 a+ R0 q9 w9 ~2 S
- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.3 F N# R: N# Y% x6 u
- // +----------------------------------------------------------------------+ s% a: _/ L/ v% f2 c
- // | Author: Juhedata <info@juhe.cn-->
5 l1 W$ t2 F8 u" `/ g3 f, c" a - // +----------------------------------------------------------------------
# k9 O9 w4 ?3 X% N4 o -
( ]" ^0 u- J, D - //----------------------------------
) ^" [5 T$ V* w - // 图像识别调用示例代码 - 聚合数据
! p' b% f6 I5 b3 o9 X: }' r! b - // 在线接口文档:http://www.juhe.cn/docs/117
8 J6 N& A5 f) p - //----------------------------------" A, U, M4 ]8 {+ p2 f- R% e. B
- ; @% T8 g- r# p2 T" J
- header('Content-type:text/html;charset=utf-8');. r9 c: x- E* v' g
-
8 v8 I+ {4 g$ d4 N$ v* p. f -
3 I9 z: d# x+ y+ [ - //配置您申请的appkey
) y2 V" s4 }( U/ j) J% n - $appkey = "*********************";5 e, m( I* u" P( s# ?# h
-
0 I0 ]3 Z" K( j -
F6 t* ^" }6 q -
* ?% M- j6 z2 @; c - , \ F( U6 }2 Y# |% J( J" d; f8 K: V1 H
- //************1.图像上传************5 ^) g V& S, W) T6 }- i3 ~$ v1 ?
- $url = "http://japi.juhe.cn/image_recognition/upload";9 W' O* E G, E5 \ [
- $params = array(3 f$ t5 u+ F2 H9 [9 l% m
- "file" => "",//上传的单张图片! n0 ~* Z) v5 @
- "key" => $appkey,//APP Key! G1 X0 z- m2 r* U+ U* L! ^" b9 w9 Q
- "pname" => "",//包名
. x4 o$ `! E* T5 Y - );
' C- w# l. n% W. N1 \" W p - $paramstring = http_build_query($params);
! l! `) j9 v s3 o- h - $content = juhecurl($url,$paramstring,1);
6 h# A7 |' w/ {& j% A: I$ ? - $result = json_decode($content,true);% \! N. o4 {5 V. W+ ~
- if($result){
$ x* T% I- C9 {: y - if($result['error_code']=='0'){! Y; v3 [+ P' I6 T
- print_r($result);: u/ R3 ~. L7 o; [& u" h
- }else{" Z/ i$ p. D6 \0 g: G
- echo $result['error_code'].":".$result['reason'];5 X8 _4 H) F- F* n& v9 k
- }2 Q1 C& M1 g$ y, v8 I
- }else{& x! E4 U' g1 k( ?# w4 ], z2 z
- echo "请求失败";; L! E+ R e5 z, W7 \0 `
- }9 l' a& k1 J( J& k" `
- //**************************************************- I h/ X0 Q- t7 E, @0 l: W
-
) |+ V7 ?; c; [- m$ l -
5 O# z4 r7 O( ]- }% o- j -
! B. O4 c; Q+ h) | -
4 n* t9 ^! Y0 E. a - //************2.查寻上传图像信息************3 X6 m% i! N* W/ M; l8 [; I
- $url = "http://japi.juhe.cn/image_recognition/findAll";
5 z9 x$ p7 m2 r5 J2 O - $params = array(. @; k9 z/ `# ]! d& z
- "key" => $appkey,//APP Key- e$ q M9 A& m
- );
; N! i N: L2 X! g: Y5 _# N# S6 h- w - $paramstring = http_build_query($params);' {, {" h. ]- N1 F1 ^% l/ c9 B
- $content = juhecurl($url,$paramstring);+ J1 W8 y7 H, z$ m4 x
- $result = json_decode($content,true);
& O4 R5 T9 K l$ Y - if($result){8 y) h4 ]; U4 M6 o
- if($result['error_code']=='0'){8 _4 @ n! V" x5 O2 x
- print_r($result);3 \. C, {+ c2 \; d9 m" v1 m
- }else{
/ w6 P; i3 n+ s2 X. t - echo $result['error_code'].":".$result['reason'];
$ x d: m6 A% g6 N - }
. ^7 A" f8 R- ?9 [ y - }else{; I' X' \4 `/ K+ ]
- echo "请求失败";
/ `' l1 B2 q! }; S - }2 ~' D. h4 V, n- n* `
- //**************************************************& s0 ^8 ^# l% l; _4 Z, s
- # A4 l* W7 N4 |+ l
- ( \7 `7 t" u) @/ M5 f- z# x4 R
-
$ Z: F |. E2 @, Q: j - % R! K7 p$ b& B7 p3 D% [
- //************3.删除图像信息************' }; ?, A: Y# T
- $url = "http://japi.juhe.cn/image_recognition/delete";. I: @6 B; f0 s1 P' F" h
- $params = array(. i0 H1 [8 C, Q0 j7 Q
- "key" => $appkey,//APP Key
7 g2 A3 j& u4 {; r% M3 R) r - "imageId" => "",//图片ID
9 _5 V4 _! Y( q; Z8 z% J - );
( n. b' r7 v" N, @5 E) [, H) ] - $paramstring = http_build_query($params);
- Y% {( `# ?/ S; e - $content = juhecurl($url,$paramstring);7 i) Y7 ~. M5 g& Q, t8 i
- $result = json_decode($content,true);4 X _: A% {8 {: ?+ _/ i" ^
- if($result){
3 p" u& h: l+ I1 r - if($result['error_code']=='0'){
0 o) O; P; f% r4 _ - print_r($result);4 D5 j, S! m8 h) W: k
- }else{
+ x$ C1 H. [2 Y, r6 \ Y - echo $result['error_code'].":".$result['reason'];
3 h+ G% C- v" e/ c - }
: X% ~' P" t' K1 z - }else{3 _' U4 i4 d5 o W
- echo "请求失败";9 D! A7 R5 C E) h: z& F! ~% x+ M
- }7 ^- n1 Z! r$ C7 t. ^ X, n$ }2 U
- //**************************************************7 L- L( H- l0 c. O* h- |( ]' S: h
-
' O+ [8 K; I8 S, U3 t' o( F8 d W/ } - ; |9 h5 k, D: N( z) [3 Z8 c
-
0 I1 L4 c; ?2 W3 B -
2 c3 C& r3 J, t+ J, E1 l- f - //************4.图像识别************: v" o- s6 z2 C/ @/ g
- $url = "http://japi.juhe.cn/image_recognition/check";$ n/ V3 d5 t6 o
- $params = array( C" k1 f% \2 D% j
- "file" => "",//上传的图片
% }0 c4 ~! ^# n/ w& E9 B+ [8 e - "key" => $appkey,//APP Key" E$ j, _3 Y, C4 d
- "pname" => "",//包名
) w* m* X3 Q8 n9 l, _ - "device_name" => "",//设备名称(如android OS或iphone OS)
. O. A% f5 |/ I; m& H - "device_version" => "",//设备版本(如:4.0.3)
8 i, V- k% k( b - "latitude" => "",//纬度; J" `5 `( r/ g6 l: Q: T {
- "longitude" => "",//经度
/ b- m0 `& Q" i) m9 o% S3 b" W7 Q; l - "uuid" => "",//设备id
' c- c m' k- P - "zone" => "",//请求地区8 F+ a% H7 O* f7 Z+ X
- );; ?# a* q5 V# h3 A
- $paramstring = http_build_query($params);; B9 f! v: R& V2 l$ u- X
- $content = juhecurl($url,$paramstring,1);
% n$ d: I# w7 k2 ?* m3 m - $result = json_decode($content,true); g: @: s) T: l+ _7 v
- if($result){
2 n; V! n* ?. _% n - if($result['error_code']=='0'){
) G& z0 H! H @" U! Q - print_r($result);
j4 r- `2 H* B, u - }else{2 l V# _3 x' H
- echo $result['error_code'].":".$result['reason'];4 ~8 o' @3 |9 e D$ ]- }) h% Q
- }
3 ]. v) T7 T1 W. A - }else{
8 G, ~8 R, g( ?0 u% [* F9 } - echo "请求失败";
+ @# O( X- s$ n% w# x& Y - }9 \- l3 Q) R: Y5 E1 f+ t
- //**************************************************3 }" _& p( a: ?3 V. D* \$ _
- . x7 ?+ H1 z( i& [7 r
- {& {6 d9 i. E+ [* j
-
2 H% ^/ t9 g" \% T0 b) K- I; V -
- k* T: G, C7 ?) V8 E -
% c) k$ I# v; S - /**
; K" z! L( F& k6 Z - * 请求接口返回内容2 a5 H+ y9 e9 n; n' u6 g3 q" N$ V
- * @param string $url [请求的URL地址]
: s5 k2 X/ j9 i5 L( t& M& K - * @param string $params [请求的参数]
s, S8 z% |! |; } - * @param int $ipost [是否采用POST形式]
( H. u+ P4 N |' C- B1 U) { - * @return string3 k+ K3 W# M0 n; |3 Z) _. L2 Z
- */
; T" r' D% D6 L; X - function juhecurl($url,$params=false,$ispost=0){
j! x4 Q5 q; X8 \% j' o% z - $httpInfo = array();
$ |/ ?# ^% `2 G - $ch = curl_init();
' \+ N2 f$ E5 j -
: c9 n, {7 G9 R, d/ S2 ~ - curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
, }0 F7 w* ?+ F) D# h9 ^ - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );- m: f/ m3 i, w0 r- z/ c
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 ); n& @/ {! ~* O
- curl_setopt( $ch, CURLOPT_TIMEOUT , 60);( Q$ Y- U: d2 x( a8 w, j6 l
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );6 _* y; d3 r8 q: _
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
' g+ {! V7 t! X - if( $ispost )
4 v; L: R% u+ l, i2 w( g* R- M4 E - {2 b2 l# n' }/ z% V; Z, [* d
- curl_setopt( $ch , CURLOPT_POST , true );
. g8 l: i* X% W0 j6 j$ V) F1 T - curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );* W% H9 u' y. U7 d. L3 a$ u; w
- curl_setopt( $ch , CURLOPT_URL , $url );
* v7 V0 _! o0 x - }' ^9 b2 e! j0 J; ^9 F
- else; p; o* V% X. Q5 [+ t
- {
?& f0 L2 t d8 I5 @2 w/ B5 y# M - if($params){8 t& ]; M C4 N7 S6 w. X
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
! f# W7 y) [' H: [ - }else{2 g0 l) Q' W9 z& _( G( H
- curl_setopt( $ch , CURLOPT_URL , $url);: Z4 Y# _4 F3 a) ?) p) {) w8 D
- }) I; I. f; R3 T% A1 m4 W
- }
' [( c3 r& c4 L& Q2 R - $response = curl_exec( $ch );
5 L8 k1 [9 q" ]/ u$ z4 c - if ($response === FALSE) {
u' d! g; F' w' e - //echo "cURL Error: " . curl_error($ch);; m0 `' i/ S2 U$ A: v- e. U+ q1 ~
- return false;
9 O [; [: d, P; U - }! @. M7 }; h6 X3 p; u6 R% C
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
! V" G R# U1 _0 v' m# a. z - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
* A# \6 I1 R4 ]+ q/ K - curl_close( $ch );
! ~7 Y( Q1 \6 h- A - return $response;( e& S7 n k. s& w% }. h+ O- z
- }
复制代码 0 M# L% ~3 b+ C/ u* u+ B* `* ]
/ l3 c1 o W% W: `% L
|
|