管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
- V- {0 d5 T- w4 {, [3 W1.添加商品信息
( q7 Z7 ?9 z7 B# |5 n* {; S$ z2.添加图片% Q2 S4 b& Y8 @* {! l8 X; V# {5 B
3.查询所有产品0 ?/ h2 u& G' b% M Y0 M5 O! [$ s
4.查询某个具体产品信息* ]2 P) T* e1 ~1 m! a+ R- n: R1 R
5.删除某个产品3 }) M" e# `" F
6.删除图片
, ]; r2 O% w$ ~7 g- c) } ?7.图像识别! S- U1 v) ?! ?- V) a' I
# c0 G. {0 |5 C, i图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey
8 P: X- R! \8 `9 v! c
' W# G; o2 |% W- k% L, {1 t# ?PHP示例:
2 ~0 i; D; [% [6 R+ C- <!--?php- s. W! f# G$ L) b. e9 j5 t$ x
- // +----------------------------------------------------------------------
+ y' g; _& w! b" z& z - // | JuhePHP [ NO ZUO NO DIE ]8 o R! h. r1 ?6 M( k) X
- // +----------------------------------------------------------------------' P9 t- ?' |6 q; M; ~! x" f. |
- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.' o+ E2 q3 ~, P+ o" c! H
- // +----------------------------------------------------------------------6 b' h; g. I( E7 H6 w; a. a1 W6 [+ J: D
- // | Author: Juhedata <info@juhe.cn-->
) w1 z- {- J x: ^ - // +----------------------------------------------------------------------
, i. i8 `1 ~( C/ M - & o2 N$ \1 Y2 J# Y* _
- //----------------------------------
" E1 K9 P3 Q3 M6 z7 i - // 图像识别调用示例代码 - 聚合数据
8 K c; ~8 [9 c9 N: p/ L& s. c - // 在线接口文档:http://www.juhe.cn/docs/117
. P2 F& I5 ?. f- l: k5 s - //----------------------------------1 I/ u$ r0 B( M# C: N t8 c
- ( r; d- h8 O. d$ G
- header('Content-type:text/html;charset=utf-8');2 Z2 J+ Z# j1 ~/ A1 \8 o1 |
-
5 G; ?8 y, n" I b( D -
, l. Z/ M e$ d; i - //配置您申请的appkey. y; S% E7 q8 e c4 m' Y
- $appkey = "*********************";
/ s, X$ \$ ~/ r! J - 1 `! Y M/ |% I$ G) Z
- & W" O1 I7 @6 X, S% p
-
% U8 Z% `& a, W& q -
0 U3 x, a: ]. O' J" y4 N - //************1.图像上传************3 `+ Q7 h) O% }3 _
- $url = "http://japi.juhe.cn/image_recognition/upload";
/ { Y& }: c7 G' W6 k5 o; o - $params = array(+ G1 L4 M4 C' X# Z5 W: a
- "file" => "",//上传的单张图片' h) V0 C- _) I2 b6 ]5 q: A
- "key" => $appkey,//APP Key
5 Z% o! B3 p' G i% K" T c, d - "pname" => "",//包名" O' k6 S8 n2 M* j# \2 `8 i
- );
; y( b* n5 G2 N: V# ^% F: M - $paramstring = http_build_query($params);/ Q& S- i) X4 K! Q. v3 s# M
- $content = juhecurl($url,$paramstring,1);
* ?# n3 T' j: F3 ^2 V1 R9 C' I - $result = json_decode($content,true);
0 E' I* K/ g2 _9 z+ ]+ q - if($result){
. X1 p! T0 P9 S, R5 u Z - if($result['error_code']=='0'){8 {0 P" i0 Y# d, O4 u U* H
- print_r($result);' q; s" G! }/ h/ q" |
- }else{* _3 Y, m0 o( a2 N/ a9 X
- echo $result['error_code'].":".$result['reason'];
' F6 Z8 {+ I; O2 }- B; U9 f6 M - }
1 q% G' G) l z# G - }else{; D& a, ]; c4 }2 A' ? ^
- echo "请求失败";1 L* B& F- Q; M; ^
- }
# ^% T5 s6 p% B' a - //**************************************************
) A/ l" k: T b8 q -
% }% u; V$ ]: y$ f% P - , i" C3 z) T: X# q* v8 v
- / t7 w; q. M& p" i$ }: D
-
( b0 ], j5 `. c+ J8 U - //************2.查寻上传图像信息************9 O) [/ a) ^ ~
- $url = "http://japi.juhe.cn/image_recognition/findAll";
5 ^0 r3 E% z9 v" p5 D - $params = array(
: ~$ ]1 f6 M. I0 j! { - "key" => $appkey,//APP Key5 K) s$ j* _# {. i% f# Z
- );
. i1 F5 g& |7 h3 x$ O. m - $paramstring = http_build_query($params);
% v4 Z9 U; @8 l4 d - $content = juhecurl($url,$paramstring);
, E- Z0 W# q8 y, X, L) P5 w - $result = json_decode($content,true);
5 ?' s: D* G- l3 O( @9 y% t9 u - if($result){
7 _* e3 g2 P) U - if($result['error_code']=='0'){; V- l% {" {& J+ c
- print_r($result);
+ r6 l" W) p6 Z - }else{
/ |! T+ z9 j7 g6 K9 Y - echo $result['error_code'].":".$result['reason'];; }. b" e% M5 l7 [; T: E5 p+ s
- }# J) Q: J: ]: \5 t: R
- }else{0 b) t( p, K' J5 ?3 L& n
- echo "请求失败";+ }! i }' [1 ]* ~
- }9 ~) F: h7 T9 T3 ]1 r
- //**************************************************1 G8 ?+ ^6 j) w# y" U3 x D2 K
-
, w* C- a6 M& w3 M -
0 _( y2 D- B/ K0 e0 W - ( G X' r" b' Z$ G W8 A+ t
-
# Y% X# J3 A3 r# _4 H0 W - //************3.删除图像信息************4 U4 l2 _4 O: I
- $url = "http://japi.juhe.cn/image_recognition/delete";
& h9 ~: o9 W# A% n' M - $params = array(- S( U# {5 S/ r. ~, m
- "key" => $appkey,//APP Key
7 D% X' I: {( X& m: h3 a, A: w - "imageId" => "",//图片ID
- g7 q2 V; |8 K) T - );! Z5 g+ _, @7 y3 a
- $paramstring = http_build_query($params);$ Y0 N# T. y0 h$ ]5 L n6 r
- $content = juhecurl($url,$paramstring);1 g8 y2 [" T! |- ^. v- h
- $result = json_decode($content,true);2 M( x( Y3 F) t3 B( L
- if($result){1 l" `. x& A& \/ K
- if($result['error_code']=='0'){
5 \2 q1 n9 j7 [. L' I5 I - print_r($result);
- R+ R/ N. ]5 v8 E% Q& m - }else{9 D* \1 R9 o4 d7 s/ x1 ]% T5 Y
- echo $result['error_code'].":".$result['reason'];
1 d7 A7 j1 _! t2 i5 l - }( M7 ~% Y# t' _
- }else{
6 V2 I$ z- [% a' ^- E; i - echo "请求失败";! C0 U: i+ Y3 D$ c/ k
- }
$ P: v1 `1 @; |$ V9 a0 [2 \# ^) h - //**************************************************
3 K$ S- R- M) w! ~ - ) i+ `3 Q6 C D
- 7 E' D+ u A, R- G5 F2 G$ P# g
-
/ l- \# `: O2 r3 m/ x3 D -
9 d7 D; {* D$ ]2 n6 o - //************4.图像识别************
' v4 I, g4 {+ G" q5 a8 x0 I7 A7 w - $url = "http://japi.juhe.cn/image_recognition/check"; X/ W6 U0 \0 H1 T, ^$ f
- $params = array() b# y! f: H$ |2 N+ t
- "file" => "",//上传的图片
% ^* |8 J8 G2 i/ {" _3 F - "key" => $appkey,//APP Key
5 M( }& M7 J* | - "pname" => "",//包名
) W c d) M8 }6 a - "device_name" => "",//设备名称(如android OS或iphone OS)
& i6 F) ~/ D6 o* c0 t' M0 \: ^# r/ f. ^5 w9 h - "device_version" => "",//设备版本(如:4.0.3)
+ a( f# E4 d o | - "latitude" => "",//纬度
3 o" P4 y S: i7 x - "longitude" => "",//经度) @' B% B- E s1 Z& `0 H( r
- "uuid" => "",//设备id( q% k* k4 a$ N
- "zone" => "",//请求地区) Y# k7 i( n8 `8 Z1 I! P9 ~
- );) m( U; r9 ]% I0 n
- $paramstring = http_build_query($params);
, f5 L8 p; D- k6 X - $content = juhecurl($url,$paramstring,1);
2 v8 f5 h1 y. J: b3 V - $result = json_decode($content,true);
4 r4 u4 H i5 d& p4 f - if($result){9 P* P0 |9 l- Q4 L4 v
- if($result['error_code']=='0'){
; t3 [/ m5 B: _8 h3 h5 V - print_r($result);3 E9 E2 n. E8 L$ M# H; ]
- }else{) ^! @( O! \, B# j
- echo $result['error_code'].":".$result['reason'];4 B6 F6 W4 }1 T) y9 i% ?
- }
' z- _+ q: a' [( v0 z/ I" H+ _ - }else{9 k7 }2 c/ \6 v, O2 O: U
- echo "请求失败";
& p8 a A# ~6 z* o9 _9 q - }* K: A f2 ^7 T" e( k$ ~+ [# ]
- //**************************************************0 I6 I& T5 Y7 b, O8 y( E
- 6 n1 g: h% v4 A8 v F' H, O
-
, G8 A8 I( U2 f) X% F' ] - ; n) S: `% q: J, S0 m
- ) r- V+ A8 A2 f) O; U5 Z& U5 x
- $ g& I* M- _ Q0 ?2 }5 r- p
- /**+ e! ?6 p& M" t( a7 D
- * 请求接口返回内容
5 D" n& V; }9 b1 y$ x% K5 b - * @param string $url [请求的URL地址]* n' }" T! v+ [( f
- * @param string $params [请求的参数]
4 _. j8 L4 g( w; B$ Q' I1 w - * @param int $ipost [是否采用POST形式]
! O% y8 I6 r& o' o - * @return string, s: I3 O0 c) c
- */4 b+ i: I' U! F$ O) i, ~" L
- function juhecurl($url,$params=false,$ispost=0){
. w1 X) w0 i) i& _0 f9 I - $httpInfo = array();
- Z; N- M7 U: X# d4 y - $ch = curl_init();5 m, \# B0 A! a* y6 ?# T& E
- 0 t8 r& n* c' i0 q
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );0 D X! I; ^. J! x
- curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );# j& |/ u' ?' e v( F n
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );0 b6 |4 K$ F8 H% y
- curl_setopt( $ch, CURLOPT_TIMEOUT , 60);' C: ~2 P3 d! ~+ w+ H4 \8 t
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );% u. B$ w5 ^* q! s9 }
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$ h O9 L H2 f/ P0 w! c - if( $ispost )# `1 U& G) \+ r1 m7 B, q- u
- {$ ^& G; q: y9 `6 v8 J
- curl_setopt( $ch , CURLOPT_POST , true );
& U. E; H& S) i* T. a$ K; E, V - curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );8 l" l+ T) i8 S5 \* A
- curl_setopt( $ch , CURLOPT_URL , $url );/ r- E; ^3 V5 s' {- }! A: P
- }
, t# l9 }5 b7 B) r8 o6 h - else
$ {4 U: n; x/ t( t4 E% v - {$ V$ L. T; s$ `) N6 w) z
- if($params){
( z+ B. ^! L1 `! A - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
( `* v/ i6 C7 C: a4 E3 a - }else{3 X% I/ W7 f( w. ]
- curl_setopt( $ch , CURLOPT_URL , $url);/ t$ n% Y0 v6 ~- t2 }
- }
' S8 u7 c9 P3 {! @/ e4 u$ T b - }7 q; D) V9 I9 G5 h) |* Q* x% G' F; c) e
- $response = curl_exec( $ch );1 ~* S; g6 E8 c+ N' p4 M
- if ($response === FALSE) {
% c& F- V: `2 M9 h8 Q6 Y, M - //echo "cURL Error: " . curl_error($ch);
\$ s' X# D- [. x5 Y$ B1 o - return false;
2 D. j% O, F( H* y ]! e7 v* O; d - }
& U) f; \ |6 W2 L7 A3 ~( d! m - $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
' E7 d0 B% `- e5 ?8 L - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );8 x. A/ h u. r/ D$ n, u
- curl_close( $ch );& c5 r+ m( P w0 Q; R) j: T' l
- return $response;
L8 I( z, v3 Y) ^, z1 z6 p* y - }
复制代码
& I* u4 |+ D0 A$ X# R% t3 }5 P9 ?% M: I% `/ |
|
|