管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
5 s5 e6 S d( U" i: l& B1.添加商品信息
# L3 ^" ~9 k0 S* R+ _; e$ a, k* Q( A% \2.添加图片
& |; Z( `" u& N3.查询所有产品* g9 d9 W: t# |6 n+ B9 c
4.查询某个具体产品信息
& H* B; z5 q. o% l& i5.删除某个产品
& E( u5 C. ?( o6.删除图片
$ x% _8 w5 X( W% |! W" g7.图像识别. D: P6 D' B/ C, e$ _3 ~
: _1 d3 u8 P4 |图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey V& M' v2 G1 q% x% a
+ W+ R$ x5 |# j! u) a- l2 t- yPHP示例:
( `0 X; v. X6 |$ F- <!--?php
/ \3 v$ ^1 N6 T6 w - // +----------------------------------------------------------------------
' K6 B) s. W0 s6 p6 r - // | JuhePHP [ NO ZUO NO DIE ]
! C. i$ M$ n* y! r1 W. S - // +----------------------------------------------------------------------! `! }' l) j% s. l( e
- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
3 v [2 p. I( f. G3 x5 N2 _" ^. a - // +----------------------------------------------------------------------$ o$ ^! j4 `9 @% }3 J+ ]' B: N
- // | Author: Juhedata <info@juhe.cn-->5 P" F) ]) R0 G- N& U0 H6 o6 ]
- // +----------------------------------------------------------------------2 K" L9 N+ I- x4 Y4 |( g
- ) O9 j' l' ^" _1 ^( a
- //----------------------------------
& A6 T( g. `, l0 M W - // 图像识别调用示例代码 - 聚合数据
) V! k8 f5 T* N) l - // 在线接口文档:http://www.juhe.cn/docs/117
7 Y2 W) K9 G$ Q1 r# Q: X% k7 ?& T - //----------------------------------
7 s# F* [, d/ V( J5 `1 v% T5 Q - ; \' |$ G2 B- o, V! Y3 \
- header('Content-type:text/html;charset=utf-8');- V; E" K3 m; h4 K
-
. {& E- S9 h' c9 H n! @5 F - 5 L% n7 D X: @" ~- ^) {# p( t# K9 f
- //配置您申请的appkey4 X( a2 s" D3 N( q# w
- $appkey = "*********************";. S/ E- G2 y4 u1 U5 U
- + m) _6 b0 B: a8 U, l- Y
- $ E2 l1 b& ~& T# o8 J4 Z9 k: Q
-
+ ^& t9 y! p+ D; b -
5 x+ D! r3 q% \ - //************1.图像上传************! D7 M' h2 R: z: G) H) k
- $url = "http://japi.juhe.cn/image_recognition/upload";+ H( _' u" |* F( M; v
- $params = array(2 ?1 ~2 b" E% P/ o9 E" V8 F, c s
- "file" => "",//上传的单张图片
) \) @) q% h3 C6 i( c8 E z4 s - "key" => $appkey,//APP Key7 g6 z+ c" ^" @: |/ q x" i( K1 Z
- "pname" => "",//包名
/ Y+ f3 a; z0 |. U - );( n8 @, N. }: Y- [0 R- L2 c" Y) R7 K
- $paramstring = http_build_query($params);( ]8 S" t: k' @. v+ r& V
- $content = juhecurl($url,$paramstring,1);& @7 R: u0 `! m$ G
- $result = json_decode($content,true);
: ~- N9 m/ ?/ f - if($result){
8 P5 K0 V- j* Y6 q - if($result['error_code']=='0'){8 m6 v0 I% R% Q5 h
- print_r($result);) x. \. m5 ~) p( A
- }else{
' E1 V. M% x; R! E - echo $result['error_code'].":".$result['reason'];# D% ~8 n) I) Q6 {. F! \
- }
1 C( v w! J+ n& w( e2 {! } - }else{/ i2 H/ d3 f5 a9 N* a
- echo "请求失败";
4 R! ^$ r4 P5 ~" ~7 c& h - }: i$ q0 X3 }5 @# T# ~9 z- G
- //**************************************************; ?6 Z, }1 E: d
- + N/ o2 y7 c% j* s0 P$ w4 s
- # Q, I$ W7 X$ }, |
- }) {3 ?# Y( J% D7 f
-
0 D; ^2 S* v* Z1 \+ t' x8 ^ - //************2.查寻上传图像信息************0 v- Q: a* p `2 s! G! g
- $url = "http://japi.juhe.cn/image_recognition/findAll";
. n( M1 a. M# j( I* I2 ` - $params = array(
* q. r3 L7 G5 J3 g7 | - "key" => $appkey,//APP Key+ q1 m/ H% l3 F. b
- );
) V* i$ e% N4 X - $paramstring = http_build_query($params);
) P# T7 N, ?3 a. |5 ~ - $content = juhecurl($url,$paramstring);
6 Z/ l$ `2 X9 f3 W3 t: K [ - $result = json_decode($content,true);5 I& n; W i. J( G
- if($result){ A; f7 E7 `! X& N1 `0 _3 \
- if($result['error_code']=='0'){
* L4 M) P8 H( x - print_r($result);# W/ w. k3 L4 y+ X6 h, R
- }else{
) _* n9 B. W2 ?, o0 S- {+ r - echo $result['error_code'].":".$result['reason'];3 @9 ]9 h/ Z4 o9 | g. J
- }
! Q9 m/ X9 d7 D- I - }else{
% X. j( G; ^# T - echo "请求失败";
- F E0 _( |, g- Z/ h - }
0 x7 f5 Y0 A5 n7 C - //**************************************************
6 A# `1 A, n* @9 F - * c5 ?' I. A& H8 j
-
- [2 p$ v8 l* C. Y& W' L, m- M - $ ?) R8 l/ I( M% _: w' ]
-
7 ]1 [8 u" ~9 P$ R9 ^5 b& Y5 g - //************3.删除图像信息************
) i* c/ q5 q+ I# C7 \& q6 D - $url = "http://japi.juhe.cn/image_recognition/delete";6 X4 v D2 D# d1 |. u
- $params = array(
' Q8 ?! @- R/ p( T4 o. y4 i) X' N - "key" => $appkey,//APP Key+ D$ {4 r F$ X% ?8 t7 l! m
- "imageId" => "",//图片ID
7 |9 u: N5 y" ?0 f, B. I( o - );/ S9 B% ?7 T7 ~& y, x1 d2 w5 X1 z
- $paramstring = http_build_query($params);$ G8 {4 |( F* ] x1 P7 f
- $content = juhecurl($url,$paramstring);0 B7 p% X3 s0 K+ p2 [
- $result = json_decode($content,true);: ~% k( J, _* O/ K. G- c
- if($result){
8 u9 ]" F `+ b" R! O - if($result['error_code']=='0'){3 q \( r `/ i }
- print_r($result);
1 y1 P! d/ D; Q; n0 }' h+ d - }else{' x+ R0 _4 d4 q$ h
- echo $result['error_code'].":".$result['reason'];" }, [8 {$ ]0 {- d% E9 O
- }
* Y8 F' t/ E" ?- u, G1 B6 e$ z - }else{
7 H1 @# l" k/ y/ f" M+ p& } - echo "请求失败";
, i- P+ H, q+ E1 ~% h% b/ q - }
" U& T; ?/ D: z+ ?/ x) U - //**************************************************: l, U. H, d/ }" Z; ^* p
-
+ D- N0 I1 W. G- J3 n -
7 O4 ~) Z% L% t# V, q - X2 T" M" ]; K6 m7 d
-
! t8 R7 q; H+ c$ E7 K, B - //************4.图像识别************. M. I, ~7 n4 N; F& B" S2 W$ J
- $url = "http://japi.juhe.cn/image_recognition/check";
! J R, D. _6 N* z6 y1 N - $params = array(
0 f) G+ P) q9 @2 A* ?" e; ^+ X* q - "file" => "",//上传的图片
+ N0 Q$ w$ b; x, L - "key" => $appkey,//APP Key' Z& Z: |! J. v% P# |
- "pname" => "",//包名
- B' C- k- s7 B1 z# G" a: {% ~ - "device_name" => "",//设备名称(如android OS或iphone OS)1 w4 y8 n$ F% W" Y8 V" `. b U3 n |
- "device_version" => "",//设备版本(如:4.0.3)
1 {. ]5 H+ n' E1 E( \ - "latitude" => "",//纬度
) N/ N% P, @2 y - "longitude" => "",//经度/ J3 i1 \' Q! s! T
- "uuid" => "",//设备id* p. g& f) E8 }* D6 b J& `
- "zone" => "",//请求地区
: p# t h G# c5 A7 O - );
! ^1 f- E2 ^, L# X$ p' ~# {1 p# f9 a - $paramstring = http_build_query($params);
, R* ]5 o2 ^' K" y: V/ a - $content = juhecurl($url,$paramstring,1);
3 v* [& t) w }* r4 r% \# l* D - $result = json_decode($content,true);; Z* O7 L6 y0 n7 p; s
- if($result){5 s$ U5 p; p8 G3 z k/ p
- if($result['error_code']=='0'){
9 ?1 X# Z# ^6 e1 n- R - print_r($result);
$ s. V: {1 v2 b$ W- o9 _ - }else{: W4 _; y: }8 g( W) p$ M1 T7 e& r' G
- echo $result['error_code'].":".$result['reason'];
- M7 k3 ?# x3 F/ I0 ^& y1 ` - }
3 H" A: f. K6 x5 b/ l2 W - }else{
7 `8 R/ \! L4 I1 k s- O) N# h - echo "请求失败";
$ A$ _5 {5 N6 \ v9 M/ [' T7 R4 R - }
7 {2 y0 [+ n6 s3 A' V3 O - //**************************************************
: m' m8 }" n J- O -
. ~1 }: X4 H: H' }& v% @2 u - 3 x2 E0 W$ J0 D! P
- 6 A: t$ J+ l! E$ I9 u, [
- 2 V% K3 U+ I8 j0 Y H0 g
- 6 H! l8 R4 G$ t3 D5 U' I
- /**
: ]0 P" q5 O5 M/ r9 E+ W- a - * 请求接口返回内容8 j9 i; _/ v, k: L
- * @param string $url [请求的URL地址]4 q/ M5 m3 p* y$ z# E9 W% J! S
- * @param string $params [请求的参数]' u3 t0 @4 s& C; e
- * @param int $ipost [是否采用POST形式]2 u& A0 V7 U: `7 b: T* E
- * @return string* ^1 j& u$ o& ?' d- ^7 A' Q: u- S
- */+ B9 k9 r/ W% R4 ^4 t' L: x2 \
- function juhecurl($url,$params=false,$ispost=0){
) c5 Y0 G2 U0 _5 b4 p/ ]. E - $httpInfo = array();
$ _& ~) v) D, k. d4 W, Z - $ch = curl_init();2 c9 w# j/ q( b/ w
-
w$ o+ t+ \1 a8 G, c - curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
8 z8 d; M. P- X N4 V5 u0 w - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
; b2 q# f* h/ E# `+ a0 |/ o - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
- w* ^0 D3 q M, z: y - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
& G+ y3 P- w4 J; ?$ d0 }& i - curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
6 N7 \ _- u# Q' A6 ~ - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);5 x C) L% j% L7 ^) x$ c' C
- if( $ispost )
, j: S* A w. M! F - {' t1 r+ i4 }; u, U
- curl_setopt( $ch , CURLOPT_POST , true ); s6 \+ k# T9 S! ?/ N: h8 v
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );* W2 Z2 u& ?5 A* J) I' [# u2 e
- curl_setopt( $ch , CURLOPT_URL , $url );: x/ E# g) a. n$ E7 G; k
- }
; y# ~) w' A( H9 b" H3 b3 | - else$ Q9 o4 C4 e. y, r1 ~4 ?
- {
/ Q& x6 [$ e: _; g - if($params){
% h' f6 ]: b6 {0 s, { - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );* e3 R# S Q) W' K, j
- }else{
' c% n9 m4 X/ G- O! @$ P - curl_setopt( $ch , CURLOPT_URL , $url);* `) f$ ~( ~" u }( U
- }2 T7 W* p. p [- ?- f* E+ q
- } n% Z* N; W8 C! Y; I
- $response = curl_exec( $ch );
. [; r9 m" B6 \! l# j e - if ($response === FALSE) {
; q# W+ H4 i4 Z5 T8 U) `( k - //echo "cURL Error: " . curl_error($ch);7 N' d- h8 g% L$ F% v' ]& C& M
- return false;* H, B! ] P) `7 @* d
- }1 N$ s9 q( O t7 f
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );4 i( C9 D) G! P& x4 Y7 M0 W. Y& v
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
& u B1 x+ ~$ ?7 N - curl_close( $ch );
$ B& }- ]) _- z# E - return $response;
1 A& E7 ~" H8 g- Q% m+ h5 K - }
复制代码 1 Y% T4 O7 i$ g" G9 h. Q9 e
/ x) G: a! ] S& n% { R h9 Z |
|