管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
7 b6 K+ b! G3 v! j( C0 C1.添加商品信息
( t$ |$ a. }& s2.添加图片
5 i. b5 A/ Z+ {+ G4 `# W3.查询所有产品
' r& d! F" Q$ d* R K% S4.查询某个具体产品信息
2 J0 L3 g- V+ Y/ C5.删除某个产品
- l& u' ]& f4 l a- Q6.删除图片8 a8 q3 `6 j/ S- g$ J
7.图像识别* X: w- p. G' C: A
1 u' g; s( M X% u
图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey
% j4 ^. j" X# d' D& ]7 p \- W+ f0 G) g9 z \
PHP示例:
6 t' N* b9 a6 C6 u c7 k: X- <!--?php2 V( W' W L- ?) J
- // +----------------------------------------------------------------------
( G& `% j# R% i8 ^3 n - // | JuhePHP [ NO ZUO NO DIE ]) N5 e% V2 d6 [4 d' v
- // +----------------------------------------------------------------------
4 w! P5 B$ I+ T. w; { - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
2 m8 Y/ q; J6 f0 i9 { - // +----------------------------------------------------------------------
! S+ Q n9 S2 d, ~9 b8 Q - // | Author: Juhedata <info@juhe.cn-->
7 _% v& I, P- V5 Q0 C. p0 i) j - // +----------------------------------------------------------------------
( L$ @. x6 K3 a/ }) K: Q -
3 E3 o! h! b4 ^# B - //----------------------------------$ A7 a9 g- u8 m' p" ~- N* {
- // 图像识别调用示例代码 - 聚合数据- ^! M0 n. W5 h8 z
- // 在线接口文档:http://www.juhe.cn/docs/117
) ~. p ?! Q# z! U - //----------------------------------
% t( m2 s7 }* F4 I3 w) D -
) r& x. j: z& }4 _ - header('Content-type:text/html;charset=utf-8');5 ^1 S8 R$ G7 ?' h
- 7 }9 H/ w: s; w& S, h3 }2 H- i
- ) h" r' `1 Y% b
- //配置您申请的appkey
0 [$ F0 I' P4 t8 f7 ~* V - $appkey = "*********************";9 I) [9 @0 f3 E& C
-
3 y: v# S6 h! {% V/ C* g m - 5 k5 Z, {6 S0 N( _5 a, M
- Q: y1 {! `* z. ~9 E8 x) }
-
9 g6 ]1 R) n, d/ c3 i9 ^ - //************1.图像上传************. J/ Y; o" ^ Q$ ?
- $url = "http://japi.juhe.cn/image_recognition/upload";
( X0 }! t7 ^( |3 Y - $params = array(
|0 _$ C! F* b* J. s6 r0 n - "file" => "",//上传的单张图片! F. Q7 J- A0 u, t) U, b
- "key" => $appkey,//APP Key' i7 ^8 [- E2 ?8 \: b9 g/ v" [
- "pname" => "",//包名
+ B0 O. E. \/ D7 @. f( R - );# c3 F8 n8 H s0 i4 ~ b. O
- $paramstring = http_build_query($params);: ^% p5 V& H' i# O! N
- $content = juhecurl($url,$paramstring,1);
7 P& g8 L) N: o+ Q. ^$ Z - $result = json_decode($content,true);
" |+ K& Z; i3 W, a/ n, L- v - if($result){
% z( x u+ h0 Z B$ ~# i) t - if($result['error_code']=='0'){
. E6 L" w/ b' A3 g5 m - print_r($result);
2 |0 P, j m6 @( C2 Z - }else{
- O1 S# ~2 y- q# [+ r' O - echo $result['error_code'].":".$result['reason'];
7 V$ n8 w: d' P" r+ v0 }+ m$ O: l# y/ i - }% [' K, |: u2 p+ l8 R4 V& y
- }else{* w, K, x J; }, }# p9 i$ C
- echo "请求失败";
8 ]9 Q" E, H4 q, F: h0 y - }
; p' \! l+ R9 i. u - //**************************************************4 o* w) n+ i- X
-
7 F- j5 q8 g" ^& W( D -
% q/ V- u& e/ o6 } - 3 w7 c$ v" t0 B7 W( i6 B
-
& M$ s4 Z2 q; M) d0 h9 p - //************2.查寻上传图像信息************
" K i5 g# M0 f& x+ o9 {* D$ y0 t - $url = "http://japi.juhe.cn/image_recognition/findAll";; e% W& T* Y' s) ?; b
- $params = array(5 z u8 v1 ~9 B5 O f
- "key" => $appkey,//APP Key$ ^' l' ?: Z- ~
- );. s- F8 t0 j& u) p( ?
- $paramstring = http_build_query($params);% Z/ G8 G0 J- g9 u8 H8 X: a$ N
- $content = juhecurl($url,$paramstring);
6 @7 j# Q) P3 E/ t. K7 q9 L - $result = json_decode($content,true);
) n/ h$ L9 Z! P; r- M$ ^- V - if($result){4 w; P2 U% L" [* q; l6 ~
- if($result['error_code']=='0'){, o# ?' D# Q9 ` x
- print_r($result);
6 r1 c. b) P# ~, A9 u - }else{
) C$ ~2 U; `) Q0 V/ m3 i$ N1 ^ - echo $result['error_code'].":".$result['reason'];( X3 x/ D" `7 o0 h% s$ z& r
- }
0 G O7 r; e( Q" _6 d6 E+ V/ a' e, O - }else{
& {8 ?& U& t0 W/ ~$ ^ - echo "请求失败";* @3 X+ G4 o3 z4 O$ ?
- }8 r( g; R" @ |7 a+ Q* m0 j, `
- //**************************************************' D7 O0 j+ S2 ?3 n
- ) J5 r8 O z! R* j, A5 A
- - b, k9 L7 L1 U& F* z. C+ W
-
6 h% L" X5 g) A. x) v$ c -
( e/ Z( P- D4 z K1 o; h - //************3.删除图像信息************. [: ^6 N/ ^( Y) k; c4 m( I$ D
- $url = "http://japi.juhe.cn/image_recognition/delete";
3 v4 ?& @$ i8 y" ~) g4 C0 t) O2 ?- } - $params = array(. D1 m* E4 w( T
- "key" => $appkey,//APP Key
4 C4 s7 N$ O* g o - "imageId" => "",//图片ID
! C# R0 h* b& W# w) { - );
/ X: H4 v) V& k, ^# a" j, `/ Q - $paramstring = http_build_query($params);
, n4 U" Z1 }4 {' E0 U' X' b - $content = juhecurl($url,$paramstring);
, u/ e$ j1 ^7 K, ~4 [ - $result = json_decode($content,true);
, Q2 k9 a% _& Z3 F+ v& Y. n" V) L - if($result){% _5 W; w: d* S+ q7 a
- if($result['error_code']=='0'){* X0 S1 O; B" K- J0 a h' Z+ F+ V' i
- print_r($result);
, L; }# |% b6 ?- w3 u% @& x - }else{
# C0 M% r2 \" ? - echo $result['error_code'].":".$result['reason'];+ d0 y* s+ `; ?8 c9 Z3 u$ b
- }
" }# b" `/ p7 O" S - }else{. |4 N6 I& p1 M- L3 e* n
- echo "请求失败";
$ }9 U8 P* ^( j2 T. R& f* [9 q - }: }, j# v% `% f& w
- //**************************************************
0 c3 `$ V0 q( P+ u -
+ E" Y" N6 r" M* Z -
9 r! R& U/ @6 \4 m4 m - ' c, e* G3 p; _6 i Y
- ) k1 D; B3 H. V* F; \ c* X
- //************4.图像识别************0 H2 I# b* z! r# W# m1 ?0 c6 g
- $url = "http://japi.juhe.cn/image_recognition/check";
2 d& V/ t' W8 } - $params = array(& E6 Y6 a; I- [) @$ p
- "file" => "",//上传的图片
, d) Y# r3 V' @7 T - "key" => $appkey,//APP Key" e& w$ i, P h+ H* v! ]' ?
- "pname" => "",//包名# a% D% g. W9 q. R) Q
- "device_name" => "",//设备名称(如android OS或iphone OS)
1 a9 `1 m" J1 Z* C' X - "device_version" => "",//设备版本(如:4.0.3)
& d/ `3 n( N) Q' b - "latitude" => "",//纬度
9 N4 i% K' ?. P% L0 ~( r - "longitude" => "",//经度0 V3 X2 q. v& r4 Q& g: s
- "uuid" => "",//设备id s" p3 D& ^: v$ }7 k& b
- "zone" => "",//请求地区
" x. Y& r% t. j2 o& u" @& O9 F - );' [1 _, q' e7 o1 T
- $paramstring = http_build_query($params);0 Y6 p. ]2 c- x' [# u* v- Q! h
- $content = juhecurl($url,$paramstring,1);
- s% u- C0 I" O; z h R' J - $result = json_decode($content,true);
+ v% M% Q0 m B) M( E- y! ~ - if($result){! ?/ @$ E5 X9 F. A+ e, r
- if($result['error_code']=='0'){
3 U1 b$ z3 _1 b" J - print_r($result);
( ^( Z/ }5 p& ^8 A - }else{( r; B" j$ Q7 T' ^1 N: ]
- echo $result['error_code'].":".$result['reason'];
, F1 M( m7 |: p3 F( V& } - }
# I, Q+ w4 V- [0 I- } - }else{
" |" L5 c- i* S2 e5 N - echo "请求失败";
. @$ x+ T Y: N" R3 q/ a - }) j- P: S3 g! C8 z+ e7 M
- //**************************************************9 ^' Y1 j9 M3 d2 |
-
. p. V. B( {: B - ' ^6 \1 c' m* T5 I3 [6 ~
-
! p5 ]" f1 x4 B* A -
4 m! H* l' k1 W& h2 f - 7 s( T& R( E% X9 b
- /**1 ^4 s- ^( |/ b) T
- * 请求接口返回内容
2 ]7 f. X0 _& Z# y2 j$ y2 m. [. S - * @param string $url [请求的URL地址]
2 F/ \+ b. q8 H0 ^ - * @param string $params [请求的参数]
+ [/ D- N+ H" ]! E W! L, r6 R8 L - * @param int $ipost [是否采用POST形式]
" ]$ X- z) e0 _# C% q - * @return string" B3 ?3 W2 w2 R) Z
- */+ h1 L& k8 I& `4 c3 Z' \
- function juhecurl($url,$params=false,$ispost=0){6 K- Y6 _6 R# P7 |& K
- $httpInfo = array();8 M% Q9 t8 S5 R0 A
- $ch = curl_init();
, n0 V: e+ X8 h4 _* u3 b - , s* s$ w" I$ j# }% X, z! A
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );0 G# v: P. @& ~! V% z
- curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );6 n5 K8 J- r3 t$ o) J2 V; O3 K5 F& E
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
+ X# k; T8 t+ Q, S7 |- L0 N& } - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
7 w. E. M+ ]% M. k0 l$ Q - curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );/ |9 y& K) |& `. ?- [1 U
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);- i9 d' ?' U+ B8 b5 `3 K
- if( $ispost )# K6 H9 n# b5 u' g( `
- {: E9 x9 ^' s% n: b1 S9 L/ {4 g
- curl_setopt( $ch , CURLOPT_POST , true );, M% Y/ v# T! g, ~0 H1 q
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
* l2 c: k# p8 n5 O' A - curl_setopt( $ch , CURLOPT_URL , $url );+ p6 t$ S1 G2 n# S; n3 q
- }
+ y& ]! L( V( a ` - else
; ~: F' f3 s9 Z. j - {
0 E; e8 j) Y2 ]& u% u - if($params){
4 |$ C- ^( }, j7 ` - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );) {- k3 ~4 A4 q7 M5 n1 c
- }else{6 X. C- [$ \+ S3 E" {* @& d. T
- curl_setopt( $ch , CURLOPT_URL , $url);
+ i' m% [4 H' Y% {( ~4 j - }! ^3 ~: j+ M; H8 f7 z! C
- }
- u5 C8 W, ?2 g, O; G4 t - $response = curl_exec( $ch );
" w9 ~; G0 B, M7 R - if ($response === FALSE) {/ N% _! `. y5 @" U2 H9 l( h
- //echo "cURL Error: " . curl_error($ch);
* R: e5 O5 g& R5 T. z& p+ t - return false;
8 I/ i& y- J4 F) m+ i& h - }
+ Q0 ^9 x3 M1 K. y ^ - $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
" C/ q; h# M! D: g - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
5 o5 T) J- | A3 G6 c - curl_close( $ch );
% |( W+ B/ `5 N7 G" F' M4 Q, O; c - return $response;
) x" z7 r3 }# B! o) F - }
复制代码 . v4 B% G+ L! b0 p
6 r1 n* A( y2 F$ T$ G1 ~% D |
|